Open a PDF from Visual Basic

K

Karl E. Peterson

Carlos said:
How do I open a PDF from Visual Basic?

Depends what you mean by "open" -- ShellExecute is the way to open it with the
default application. Here, change "print" to "open" and this'll do:

Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation
As String, ByVal lpFile As String, ByVal lpParameters As String,
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Public Function PrintDoc(ByVal DocFile As String) As Long
' Uses the "print" verb as defined in the registry
PrintDoc = ShellExecute(0&, "print", DocFile, vbNullString, vbNullString,
vbNormalFocus)
End Function

From http://vb.mvps.org/samples/HyperJmp
 
C

Carlos

Thanks a lot Karl. Perhaps I should have said that I am using Visual Basic
from Office.

I found that "following an hyperlink" also works, AS MENTIONED in other
posts. However, I had to change my macro security settings to prevent Excel
from warning me "not to open untrusted hyperlinks". In particular, to allow
Excel to trust in Visual Basic proyects (Tools / Options / Macro Security /
Trusted Editors).

My final code is:

Option Explicit
Dim wbk As Workbook

Set wbk = ActiveWorkbook
Call wbk.FollowHyperlink(FileName)

End Sub

All this stuff about security makes things really fuzzy, specially if you
want to share your applications and I am not sure if the next version of
Office will support the same method.
 
K

Karl E. Peterson

Carlos said:
Thanks a lot Karl. Perhaps I should have said that I am using Visual Basic
from Office.

ShellExecute oughta work just fine, there, too.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top