Solved

Open PDF file and goto a specific page

Posted on 2008-10-28
2
2,561 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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now