valixpacc
asked on
ShellExecute VBA
Hi Experts,
I'm using this VBA code and I'm trying to open a pdf file from MS Access 2007 form.
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
If I use this line no issues:
ShellExecute 0, "Open", "C:\Temp\myfile.pdf", "", "", vbNormalNoFocus
However this is what I need since the path name can change..
filename=CurrentProject.Pa th & "\myfile.pdf"
ShellExecute 0, "Open", filename, "", "", vbNormalNoFocus
Is that possible ?
Thank you,
I'm using this VBA code and I'm trying to open a pdf file from MS Access 2007 form.
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
If I use this line no issues:
ShellExecute 0, "Open", "C:\Temp\myfile.pdf", "", "", vbNormalNoFocus
However this is what I need since the path name can change..
filename=CurrentProject.Pa
ShellExecute 0, "Open", filename, "", "", vbNormalNoFocus
Is that possible ?
Thank you,
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i think rgonzo is correct, sorry misread your post.
ASKER
Thank you for your answers.
I already did that ( all variables are declared).
This won't solve the problem even I specify the full path of Acrobat Reader.
Again I wil explain:
Dim filename As String
filename = CurrentProject.Path & "\myfile.Pdf"
'' no problem here
Shell "C:\Program Files\Adobe\Reader 10.0\Reader\AcroRd32.exe" & " " & "C:\Temp\myfile.pdf", vbNormalFocus
'' this is not working
Shell "C:\Program Files\Adobe\Reader 10.0\Reader\AcroRd32.exe" & " " & filename, vbNormalFocus
OR
Application.FollowHyperlin k "C:\Temp\myfile.pdf" -- working
Application.FollowHyperlin k filename -- not working
So looks like no matter what approach I choose I need to specify the name of the file and the path instead of a variable wich doesn't solve the issue.
I already did that ( all variables are declared).
This won't solve the problem even I specify the full path of Acrobat Reader.
Again I wil explain:
Dim filename As String
filename = CurrentProject.Path & "\myfile.Pdf"
'' no problem here
Shell "C:\Program Files\Adobe\Reader 10.0\Reader\AcroRd32.exe" & " " & "C:\Temp\myfile.pdf", vbNormalFocus
'' this is not working
Shell "C:\Program Files\Adobe\Reader 10.0\Reader\AcroRd32.exe" & " " & filename, vbNormalFocus
OR
Application.FollowHyperlin
Application.FollowHyperlin
So looks like no matter what approach I choose I need to specify the name of the file and the path instead of a variable wich doesn't solve the issue.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
followhyperlink CurrentProject.Path & "\myfile.pdf"
if you want to use shell, you need to know the path to your pdf (acrobat ) reader