Const cAdobeReaderExe As String = "C:\Program Files (x86)\Adobe\Acrobat 11.0\Acrobat\Acrobat.exe"
Public Sub Open_PDF_At_Page()
Dim PDFfile As String
Dim AdobeCommand As String
PDFfile = "C:\path\to\PDF document.pdf"
AdobeCommand = " /a ""page=2=Open Actions"" "
Shell cAdobeReaderExe & AdobeCommand & Chr(34) & PDFfile & Chr(34), vbNormal
End Sub
Hi John, I was trying to use this code with my Mac. But its not working there. Any suggestions ?Try this, changing the Acrobat.exe (or Adobe Reader) path and PDF file name as required.
Code:Const cAdobeReaderExe As String = "C:\Program Files (x86)\Adobe\Acrobat 11.0\Acrobat\Acrobat.exe" Public Sub Open_PDF_At_Page() Dim PDFfile As String Dim AdobeCommand As String PDFfile = "C:\path\to\PDF document.pdf" AdobeCommand = " /a ""page=2=Open Actions"" " Shell cAdobeReaderExe & AdobeCommand & Chr(34) & PDFfile & Chr(34), vbNormal End Sub
Try this, changing the Acrobat.exe (or Adobe Reader) path and PDF file name as required.
Code:Const cAdobeReaderExe As String = "C:\Program Files (x86)\Adobe\Acrobat 11.0\Acrobat\Acrobat.exe" Public Sub Open_PDF_At_Page() Dim PDFfile As String Dim AdobeCommand As String PDFfile = "C:\path\to\PDF document.pdf" AdobeCommand = " /a ""page=2=Open Actions"" " Shell cAdobeReaderExe & AdobeCommand & Chr(34) & PDFfile & Chr(34), vbNormal End Sub
Shell Chr(34) & cAdobeReaderExe & Chr(34) & AdobeCommand & Chr(34) & PDFfile & Chr(34), vbNormal
This can be done with the Worksheet_FollowHyperlink event handler, but with the link created in a particular way which allows the code to override the default action of clicking a link. In this example, create the link in cell A7 with the following properties:I'm currently using Adobe DC (2015) and would like to open a specific page in from a PDF refrence document via a link in excel (Office 365). I would certainly appreicate any help you could give..
Thx,
Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPtr
Private Declare PtrSafe Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
(ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
#Else
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
Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
(ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
#End If
Public Sub Open_PDF_At_Page(PDFfile As String, Optional page As String = "1")
Dim PDFexe As String
Dim AdobeCommand As String
PDFexe = Get_ExePath(PDFfile)
AdobeCommand = " /a ""page=" & page & "=Open Actions"" "
Shell Chr(34) & PDFexe & Chr(34) & AdobeCommand & Chr(34) & PDFfile & Chr(34), vbNormal
End Sub
Private Function Get_ExePath(lpFile As String) As String
Dim lpDirectory As String, sExePath As String, rc As Long
lpDirectory = "\"
sExePath = Space(255)
rc = FindExecutable(lpFile, lpDirectory, sExePath)
Get_ExePath = Left$(sExePath, InStr(sExePath, Chr$(0)) - 1)
End Function
Option Explicit
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
Open_PDF_At_Page Target.ScreenTip, Range("A10").Value
End Sub
Thanks John - Doesn't seem to like the Shell statement again...
Run time error '5' - invalid procedure call or argument without quotes around exe (PDFexe)
Run-time error '53' - file not found with quotes around exe ("PDFexe")
Chr(34) & PDFexe & Chr(34)
puts quotes around the .exe.Public Sub Open_PDF_At_Page(PDFfile As String, Optional page As String = "1")
Dim PDFexe As String
Dim AdobeCommand As String
If Dir(PDFfile) <> vbNullString Then
PDFexe = Get_ExePath(PDFfile)
AdobeCommand = " /a ""page=" & page & "=Open Actions"" "
Shell Chr(34) & PDFexe & Chr(34) & AdobeCommand & Chr(34) & PDFfile & Chr(34), vbNormal
Else
MsgBox PDFfile & " doesn't exist", vbExclamation
End If
End Sub