Open PDF file and goto a specific page


From VBA in Excel 2007 I want to open a pdf file in Adobe Reader (outside Excel). That work ok. But when I try to use parameter to specify a page number, zoom etc. it does not do what I expect.

From shell the following work successful:
AcroRd32.exe /A "page=2,zoom=100"  "C:\Tmp\manual.pdf"

In VBA I use ShellExecute API function:
sParam = "/A " & Chr(34)  & "page=2,zoom=100" & Chr(34)
Call ShellExecute(0&, "Open", "c:\tmp\manual.pdf", sParam, vbNullString, SW_SHOWNORMAL)

It opens the pdf file, but ignores the parameters.

If I open the url "c:\tmp\manual.pdf#page=2&zoom=90" in Internet Explorer (use the Shell function in Excel), it work as expected.

My question is: How can I open a pdf file with parameters (page,zoom, nameddest etc) from Excel VBA?
Who is Participating?
tselectroConnect With a Mentor Author Commented:

I get error 429 in VBA when trying your solution (ActiveX component can't create object).

I have do some experiment with the ShellExecute and have find one solution. Following code do what I want:

sParam = " /A " & Chr(34) & "page=1&zoom=100&pagemode=bookmarks" & Chr(34) & "C:\tmp\manual.pdf"
Call ShellExecute(0&, "open", "AcroRd32.exe", sParam, "", SW_SHOWNORMAL)
From a quick search around I believe this can be done:  I found this code on another Experts Call that covers what you wish to do.  If this fails but it works in an browser why don't you use the browser option - shell command it to open it and then give it the URL?

Dim AVDoc As Acrobat.CAcroAVDoc
Dim AVPageView As Acrobat.CAcroAVPageView
Dim AcroApp As Acrobat.CAcroApp
Set AcroApp = CreateObject("AcroExch.App")
Set AVDoc = CreateObject("AcroExch.AVDoc")

AVDoc.Open(URL, "")

Set AVPageView = AVDoc.GetAVPageView
All Courses

From novice to tech pro — start learning today.