Launch another application from User Form??

M

Marie

Hi,

Is there a way to launch a PDF file in Adobe Acrobat by
clicking on a command button in a Word VBA form? I can't
find out how to launch another application from within
Word using a user form. I'm also going to leave this
message on the VBA General newsgroup.

TIA

Marie
 
J

Jay Freedman

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top