Re: Open a pdf file from VB 6.0
- From: "MikeD" <nobody@xxxxxxxxxxx>
- Date: Thu, 11 May 2006 20:19:50 -0400
"Jim Y" <j.s.yablonsky@xxxxxxxxxxxxxx> wrote in message news:i3P8g.83314$eR6.63603@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
"Chevy" <Chevy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:F7E33DE5-791A-446E-BABF-270AD05F9DE9@xxxxxxxxxxxxxxxx
Hi,
How I do to open a pdf (c:\myPDF.pdf) from a VB 6.0 form.
I try with Shell function someting like
Call Shell("c:\myPDF.pdf", vbMaximizedFocus)
but raise this error "Error procedure call or arguments"
There is way to show a pdf file in a control within a VB 6.0 Form?
thanks in advance....
--
Eusebio
As long as you have Acrobat Reader installed on your PC, the following should work for you. This code works in my program. The Auto Manual.pdf file is in the programs folder.
Jim Y
=============================
Private Sub mnuManual_Click()
On Error Resume Next
CommonDialog2.DialogTitle = "Open PDF document"
CommonDialog2.CancelError = True
CommonDialog2.InitDir = App.Path
CommonDialog2.FileName = "Auto Manual.pdf"
If Err = cdlCancel Then
' The user has selected the cancel button.
' So do nothing.
Else
' A document has been selected.
AcrobatShowPDFdocument App.Path & "\Auto Manual.pdf"
End If
On Error GoTo 0
End Sub
Just a couple little nitpicks....
First, Err.Number is preferred over the Err function.
Second, you should ALWAYS check for a trailing backslash in App.Path. If your application happens to get installed to the root folder (or is installed on a network share and mapped to a drive letter), then App.Path will already have a trailing backslash and your code, as is, will fail.
Third, uh.....maybe I missed it, but where's the code for the AcrobatShowPDFdocument sub? That's really the important code to provide. <g>
Fourth, there's absolutely no reason to disable error handling immediately before an End Sub (or End Function, or Exit Sub|Function).
Fifth, it looks like you left out more code, like 'CommonDialog2.ShowOpen'. And why prompt for a file name if the name of the PDF file you want to open is already known? <g>
Sorry, I just found these anamolies amusing. I realize you're just posting example code and nobody expects it to be perfect. But, you did omit the most important part.....the code that actually opens the PDF file in Acrobat Reader. Paul already provided the solution (the ShellExecute API function), so I won't bother with an example for that.
--
Mike
Microsoft MVP Visual Basic
.
- Follow-Ups:
- Re: Open a pdf file from VB 6.0
- From: Jim Y
- Re: Open a pdf file from VB 6.0
- References:
- Re: Open a pdf file from VB 6.0
- From: Jim Y
- Re: Open a pdf file from VB 6.0
- Prev by Date: Windows Vista Trends
- Next by Date: Re: Question about an object array
- Previous by thread: Re: Open a pdf file from VB 6.0
- Next by thread: Re: Open a pdf file from VB 6.0
- Index(es):