Hi guys
The suggestion is in the right direction, but the syntax is a bit flawed.
First, delete the parentheses -- they're valid only if you're getting a
return value from the function. Second, the Shell function defaults to
showing the launched app in a minimized window; to be able to see it right
away, include the optional second argument with a value of vbNormalFocus (a
constant equal to 1).
Finally, and more important, most users don't have Acrobat (the expensive
authoring app), they have AcroRd32.exe (the free reader). To go further, if
this macro is for use by other PCs, you don't necessarily know the path to
AcroRd32 because they could have installed it anywhere. You can use the
PrivateProfileString function to dig into the registry and find the path to
whatever app is registered to handle PDF files.
Private Sub LaunchPDF(strDoc As String)
Dim strCmd As String
strCmd = System.PrivateProfileString("", _
"HKEY_CLASSES_ROOT\AcroExch.Document\shell\Open\command", _
"")
If Len(strCmd) > 0 Then
strCmd = Replace(strCmd, "%1", strDoc)
Shell strCmd, vbNormalFocus
Else
MsgBox prompt:="Could not find an application" & vbCr & _
"registered to display PDF files.", _
Buttons:=vbCritical + vbOKOnly, _
Title:="Not Registered"
End If
End Sub
Public Sub TestPDF()
LaunchPDF "c:\docs\mydoc.pdf"
End Sub