Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Starting an acrobat reader and passing it the name of a pdf 1

Status
Not open for further replies.

jimsterS

Programmer
Apr 24, 2001
71
US
I want to be able to pass the name of a PDF to open it programmatically. It seems that the shell function will allow me to open PDF reader but I can't figure how to pass it a pdf name.

Thanks
Jim
 
I use a variety of routines to open up PDF files using the Shell function. First, I have a group of functions to check the Windows registry for the location of Acrobat Reader. (I'm not going to post all the Registry access code here--you can use whatever technique you like to locate the program.) The point is that you get the "open" command string for Acrobat Reader. It usually looks like:
Code:
"C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe" "%1"
Then, I replace the "%1" parameter of the open command with the name of the PDF file to view, and put double quotes around the name. Then, I use the Shell function to execute the final command line string. For example:
Code:
Function AcroRdOpen(sPDFName As String, _
                    lWindowFocus As Long) As Boolean
  Dim sOpenCmd  As String
  Dim sShellCmd As String
  Dim i As Integer
  Dim result
  
  On Error Resume Next
  AcroRdOpen = True
  'Get AcroRd32 "open" command from Windows Registry
  sOpenCmd = gcAcroRdOpen()
  '(Error checking omitted here for brevity)
  i = InStr(sOpenCmd, "%1") 
  If i > 0 Then
    sShellCmd = Left(sOpenCmd, i - 1) _
              & Chr(34) & sPDFName & Chr(34)
  Else
    sShellCmd = sOpenCmd & " " _
              & Chr(34) & sPDFName & Chr(34)
  End If
  result = Shell(sShellCmd, lWindowFocus)
  AcroRdOpen = (result = 0)
End Function
I hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top