How to open one program or the other

  • Thread starter Thread starter Garyj
  • Start date Start date
G

Garyj

Guest
Here is the code that I am running. How do I get the code to open either Acrobat 4 or Acrobat 5 if it does find one or the other.


Private Sub Command23_Click()
On Error GoTo Err_Command23_Click

Dim stAppName As String

stAppName = "C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe x:\shared\jobg\acct\exhibit\acct4.pdf"
Call Shell(stAppName, 1)

Exit_Command23_Click:
Exit Sub

Err_Command23_Click:
MsgBox Err.Description
Resume Exit_Command23_Click
End Sub
 
Use ShellExecute API... It opens the file you specify with whatever default program is associated with it (whether it be Acro 4,5 or 6):


Private Declare Sub 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)

Private Const SW_HIDE = 0
Private Const SW_MAXIMIZE = 3
Private Const SW_MINIMIZE = 6
Private Const SW_RESTORE = 9
Private Const SW_SHOW = 5
Private Const SW_SHOWDEFAULT = 10
Private Const SW_SHOWMAXIMIZED = 3
Private Const SW_SHOWMINIMIZED = 2
Private Const SW_SHOWMINNOACTIVE = 7
Private Const SW_SHOWNA = 8
Private Const SW_SHOWNOACTIVATE = 4
Private Const SW_SHOWNORMAL = 1

Private Sub Command23_Click()

ShellExecute 0, "Open", "Path of file goes here", vbNullString, vbNullString, SW_SHOWDEFAULT

End Sub
 
Last edited:
In the area where you marked "Path of file goes here" is that my document path or the path where acrobat resides?

Thanks
 
It's the path of the file. You don't need to put in the name of the application as the functions looks in the registry to see what application is associated with that file extension (so it works with any file - .doc, .bmp, .mp3, .pdf etc....)

Jordan
 
Application.FollowHyperlink will also use the default program.

Application.FollowHyperlink "x:\shared\jobg\acct\exhibit\acct4.pdf"

HTH
 
:D I like it....... :D

I must admit I tend to jump on the API wagon far too quickly..... :rolleyes:
 
How will this fit in the code that I have posted.

Application.FollowHyperlink "x:\shared\jobg\acct\exhibit\acct4.pdf"


Thanks
 

Users who are viewing this thread

Back
Top Bottom