Solved

open .pdf from VB

Posted on 2001-06-19
10
848 Views
Last Modified: 2007-11-27
I want to open a pdf file from within VB.  I know the path & file name.  Unfortunately, the Shell command doesn't appear to know what to do with
   Shell "c:\somewhere\report.pdf"

The only way I've found to make this work is to supply both the fully-qualified path to AcroRd32.exe and my pdf file, delimiting the pdf file/path with double-quotes:
   Shell "C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe" & chr$(34) & "c:\somewhere\report.pdf" & chr$(34)
Yuck!

Enough info?
0
Comment
Question by:Believer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6207450
You could use the active X control that comes with acrobat!
It has a method called openfile that shows the file.
0
 
LVL 5

Expert Comment

by:jklmn
ID: 6207600
Hi,

Have you try:

Shell "start c:\somewhere\report.pdf"
0
 
LVL 2

Accepted Solution

by:
agriggs earned 100 total points
ID: 6207771
You can use the ShellExecute API function.  It automatically looks up the extension for the file that you specify and launches the appropriate application.  (The same way that Start does.)

ShellExecute "resume.doc"  'launches word
ShellExecute "expense.xls" 'launches excel
ShellExecute "report.pdf"  'launches acroread

Look it up in the API text viewer for the exact specifications.

0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 7

Author Comment

by:Believer
ID: 6208067
wow, lots of really neat ideas...
I tried referencing the OCX and it's not showing up in my toolbox.  will try the latter two options and get back to you.  (I rather like the idea of not having to reference another ocx...)

Thanks!
0
 
LVL 7

Author Comment

by:Believer
ID: 6208338
jklmn: I kept getting a "file not found" error, even with a real easy "c:\a.pdf" so I think the shell command didn't know what to do with "start".

agriggs: You rock!  I had to do some research on the API, but it was relatively easy to find on MSDN.  (For future reference, this is the KB that got me going: http://support.microsoft.com/support/kb/articles/Q170/9/18.asp)  It wasn't quite as easy as your examples, but I'm still a happy camper.

Quick resolution is very much appreciated... thanks to everyone!
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6208352
You do what you want but, anyway, you need acrobat installed on target machines to get all others comments.
What is the problem with ocx?
If you don't want to use it, just do a little simple:

shell "start c:\mydocuments\mypdf.pdf", vbnormal

will opens the file if you have acrobat installed, just like  jklmn comment.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6208399
Anyway, you didn't open pdf file "inside" VB, just creates an instance of acrobat and you don't have control over it actually.
Cheers.
0
 
LVL 7

Author Comment

by:Believer
ID: 6208553
When I referenced the OCX in my VB application, it wasn't showing up as a control I could drop on the form.  I assumed it would work like the File Dialog ActiveX where you put the invisible control on your form.  If not, I apologize!

I know Acrobat needs to be installed - that's a pre-requisite for the users who install the application.

Like I said, the "shell start" wasn't behaving for me.  Since the API behaved as expected when I tried it, I went with that.
0
 

Expert Comment

by:asmahmood
ID: 6224512
Try using following code i work with this code it does not need any api or so.


dim quality
quality = Shell("C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe", vbMaximizedFocus)
    SendKeys "^o", True
    SendKeys "c:\asmahmood.pdf", True
    SendKeys "{ENTER}", True
    SendKeys "%R", True


0
 
LVL 7

Author Comment

by:Believer
ID: 6230846
Thanks, but no thanks.  I all but refuse to use sendkeys on religious grounds. <G>  Also looks like you are relying on a hard-coded path to Acrobat.exe.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month4 days, 18 hours left to enroll

636 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