Solved

Open PDF file and goto a specific page

Posted on 2008-10-28
2
2,602 Views
Last Modified: 2012-05-05
Hello

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?
0
Comment
Question by:tselectro
2 Comments
 
LVL 17

Expert Comment

by:wobbled
ID: 22820285
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?


http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_20949436.html

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
AVPageView.Goto(4)
0
 

Accepted Solution

by:
tselectro earned 0 total points
ID: 22822584
Hello

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)
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question