PDA

View Full Version : Opening a Pdf file using VBA



littleiitin
11-30-2011, 02:11 PM
Hi All,

I need a vba code to open a pdf file.
I have a code which incliudes API Call.




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





Sub OpenPDFFile()

Dim strFilePath As String

strFilePath ="C:\Temp\MyPdf.pdf"
ShellExecute 0, "Open", strFilePath, "", "", vbNormalNoFocus
End Sub





Is there any other method to open pdf file using VBA?

Thanks
Rahul Singh

Admin
11-30-2011, 02:48 PM
Hi,

You could try something like


Sheet1.Hyperlinks.Add Range("A2"), "C:Temp\MyPDF.pdf"
Range("A2").Hyperlinks(1).Follow NewWindow:=1

littleiitin
11-30-2011, 03:05 PM
OH...

Hyperlink.

Thanks Admin for letting me remember.