open pdf file through vba

  • Thread starter Thread starter damv
  • Start date Start date
D

damv

Hello everyone,

I have a table and in a field i have the path of a pfd file (eg
c:\files\1.pdf). In a form i have this information of the path. I wan
to create a button so i can open that file. After a search i made i
the forume i found some information about "shellexecute API" but i ca
not make it work. Please help!

Thanks in advance
 
Damv,

Using a macro, the way to do this is a RunApp action. The Command Line
argument would look something like...
"C:\Program Files\Adobe\AcroRd32.exe" "c:\files\1.pdf"

Another approach would be to set the data type of the field in table
design to Hyperlink, and enter your data with the File protocol
indicator, e.g.
File:c:\files\1.pdf
and then you could just click on the data on the form to open the file.
 
'In a module declaration
Private Declare Function ShellExecute 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


Public Function ShellExec(ByVal sFIle As String, _
Optional ByVal eShowCmd = 0, _
Optional ByVal sParameters As String = "", _
Optional ByVal sDefaultDir As String = "", _
Optional sOperation As String = "open", _
Optional Owner As Long = 0 _
) As Long
Dim lR As Long
Dim lErr As Long, sErr As Long
lR = ShellExecute(Owner, sOperation, sFIle, sParameters, sDefaultDir,
eShowCmd)
End Function


'Usage
private sub Button1_Click()

ShellExec "c:\files\1.pdf"

end sub

'If the machine that this runs on has Acrobat installed and pdf is
associated to it, then this will work. It can be used to launch any
file in its default application (if associated).
 
Back
Top