Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Leggere da Access file in modalità solo lettura

65 views
Skip to first unread message

lismax

unread,
Apr 22, 2003, 3:50:36 PM4/22/03
to
Per l'apertura dei file da Access uso la funzione sotto indicata (utilizza
le API) che trovo molto utile, in quanto consente di richiamare i files a
seconda dell'estensione e soprattutto senza la necessità di inserire i
riferimenti. Di conseguenza vengono letti tutti i file Word , Excel ecc.
qualsiasi sia la versione.

Il quesito che pongo è questo.
Chi sa modificare la funzione sotto indicata facendo in modo che i file Word
e Excel vengano letti in modalità solo lettura ?

----------------------------------------------------------------------------
--
'(Q) How do I start the application which is registered to handle a file
' extension in Win Registry?

'(A) You'll have to use the ShellExecute API. Pass the filename
'to fHandleFile function. If the file extension is "known",
'or registered, it should automatically call the parent
application.

'If the extension is unknown, it should bring up the
'Windows standard "Open With" dialog box.

'************ Code Start **********
Private Declare Function apiShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" _
(ByVal hWnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) _
As Long

'***App Window Constants***
Public Const WIN_NORMAL = 1 'Open Normal
Public Const WIN_MAX = 3 'Open Maximized
Public Const WIN_MIN = 2 'Open Minimized

'***Error Codes***
Private Const ERROR_SUCCESS = 32&
Private Const ERROR_NO_ASSOC = 31&
Private Const ERROR_OUT_OF_MEM = 0&
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&

'***************Usage Examples***********************
'Open a folder: ?fHandleFile("C:\TEMP\",WIN_NORMAL)
'Call Email app: ?fHandleFile("mailto:das...@hotmail.com",WIN_NORMAL)
'Open URL: ?fHandleFile("http://home.att.net/~dashish", WIN_NORMAL)
'Handle Unknown extensions (call Open With Dialog):
' ?fHandleFile("C:\TEMP\TestThis",Win_Normal)
'Start Access instance:
' ?fHandleFile("I:\mdbs\CodeNStuff.mdb", Win_NORMAL)
'****************************************************

Function fHandleFile(stFile As String, lShowHow As Long)
Dim lRet As Long, varTaskID As Variant
Dim stRet As String
'First try ShellExecute
lRet = apiShellExecute(hWndAccessApp, vbNullString, _
stFile, vbNullString, vbNullString, lShowHow)

If lRet > ERROR_SUCCESS Then
stRet = vbNullString
lRet = -1
Else
Select Case lRet
Case ERROR_NO_ASSOC:
'Try the OpenWith dialog
varTaskID = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL "
& stFile, WIN_NORMAL)

lRet = (varTaskID <> 0)
Case ERROR_OUT_OF_MEM:
'stRet = "Error: Out of Memory/Resources. Couldn't Execute!"
stRet = "Errore: Out of Memory/Resorse. Impossibile
Eseguire! "

Case ERROR_FILE_NOT_FOUND:
'stRet = "Error: File not found. Couldn't Execute!"
stRet = "Errore: File non trovato. Impossibile Eseguire!"
Case ERROR_PATH_NOT_FOUND:
'stRet = "Error: Path not found. Couldn't Execute!"
stRet = "Errore: Percorso non trovato. Impossibile Eseguire!
"

Case ERROR_BAD_FORMAT:
'stRet = "Error: Bad File Format. Couldn't Execute!"
stRet = "Errore: Formato del file errato. Impossibile
Eseguire! "

Case Else:
End Select
'Visualizza un messaggio se ci sono problemi con la guida
MsgBox stRet, vbOKOnly & vbInformation, "IMPREVISTO nell'apertura
del file"

End If
fHandleFile = lRet & _
IIf(stRet = "", vbNullString, ", " & stRet)
End Function


Giorgio prx

unread,
Apr 23, 2003, 4:37:45 AM4/23/03
to

"lismax" <lismax...@tiscali.it> ha scritto nel messaggio
news:g2hpa.58505$iy5.1...@twister2.libero.it...

> Per l'apertura dei file da Access uso la funzione sotto indicata (utilizza
> le API) che trovo molto utile, in quanto consente di richiamare i files a
> seconda dell'estensione e soprattutto senza la necessità di inserire i
> riferimenti. Di conseguenza vengono letti tutti i file Word , Excel ecc.
> qualsiasi sia la versione.
>
> Il quesito che pongo è questo.
> Chi sa modificare la funzione sotto indicata facendo in modo che i file
Word
> e Excel vengano letti in modalità solo lettura ?
>

Ciao
Hanno inventato l'automazione per fare queste cose, ed è possibile non
utilizzare i riferimenti.

'Apre un doc di word in sola lettura senza riferimenti
Sub Apri_Word()
Dim Wrk As Object
Dim WrkNewDoc As Object
Set Wrk = CreateObject("Word.Application")
Set WrkNewDoc = Wrk.Documents.Open("C:\Documenti\Doc1.doc", , True)
Wrk.Visible = True
Set WrkNewDoc = Nothing
Set Wrk = Nothing
End Sub

'Apre un foglio di excel in sola lettura senza riferimenti
Sub Apri_Excel()
Dim xlApp As Object
Dim wkbNewBook As Object
Set xlApp = CreateObject("Excel.Application")
Set wkbNewBook = xlApp.Workbooks.Open("C:\Documenti\Cartella1.xls", ,
True)
xlApp.Visible = True
wkbNewBook.Activate
Set wkbNewBook = Nothing
Set xlApp = Nothing
End Sub

Ciao Giorgio

lismax

unread,
Apr 23, 2003, 10:50:28 AM4/23/03
to

"Giorgio prx" <giorgio...@tiscalinet.it> ha scritto nel messaggio
news:b85j8o$fd8$1...@lacerta.tiscalinet.it...
Ti ringrazio : io per aprire Word digitavo.
Dim WrK as Word.Application
Dim WrkNewDoc As Word.Document
Set Wrk = CreateObject("Word.Application.8")
... e quindi ero costretto a mettere Word tra i rifermenti con tutti i
casini connessi alle diverse versioni di Word..

Cmq la funzione API oltre ad essere + veloce è anche più pratica se si ha
la necessità di aprire files con estensioni diverse (doc,xls,jpg,htm ecc.)

Se qualcuno pratico di API sa come modificare la funzione per consentire che
i file Word vengano aperti in sola lettura raggiungeri l'optimum.

Giorgio prx

unread,
Apr 24, 2003, 3:42:51 AM4/24/03
to

"lismax" <lismax...@tiscali.it> ha scritto nel messaggio
news:UKxpa.61092$DT4.1...@twister1.libero.it...

>
> "Giorgio prx" <giorgio...@tiscalinet.it> ha scritto nel messaggio
> news:b85j8o$fd8$1...@lacerta.tiscalinet.it...
> >
> > "lismax" <lismax...@tiscali.it> ha scritto nel messaggio
> > news:g2hpa.58505$iy5.1...@twister2.libero.it...
[CUT]

> Cmq la funzione API oltre ad essere + veloce è anche più pratica se si ha
> la necessità di aprire files con estensioni diverse (doc,xls,jpg,htm ecc.)
>
> Se qualcuno pratico di API sa come modificare la funzione per consentire
che
> i file Word vengano aperti in sola lettura raggiungeri l'optimum.
>

Il problema non è relativo alla funzione api, bisognerebbe conoscere il
parametro da passare a Word tramite la linea di comando.

Ciao Giorgio.

lismax

unread,
Apr 24, 2003, 11:05:43 AM4/24/03
to

"Giorgio prx" <giorgio...@tiscalinet.it> ha scritto nel messaggio
news:b884dp$m93$1...@lacerta.tiscalinet.it...
Appunto. Il problema è come passare il valore True a Word tramite API :
0 new messages