![]() |
#1
|
|||
|
|||
![]()
I am trying to create a Word 2016 VBA macro that goes to a specific page in a hyperlinked PDF when the page number is part of the hyperlink address.
The most I could find on the subject is at https://stackoverflow.com/questions/...from-word-2013. The solution offered there is not of interest to me because I need the PDF to open with either FoxitPDF reader or SumatraPDF—not an internet browser. But one user at that link offered the following VBA macro solution: Code:
Sub [Name Of Script]() Dim targetLink As String Dim targetName As String Dim pageNumber As Integer Dim pathPDF As String targetName = Selection.Hyperlinks(1).Name parts = Split(targetName, "page=") pageNumber = parts(1) pathPDF = Selection.Hyperlinks(1).Address Call OpenPagePDF(pathPDF, pageNumber) End Sub Public Function OpenPagePDF(sMyPDFPath As String, iMyPageNumber As Integer) Dim RtnCode, AdobePath As String AdobePath = "C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" RtnCode = Shell(AdobePath & " /a " & Chr(34) & "page=" & iMyPageNumber & "=OpenActions" & Chr(34) & " " & Chr(34) & sMyPDFPath & Chr(34), 1) End Function Code:
Sub [Name Of Script]() Dim targetLink As String Dim targetName As String Dim pageNumber As Integer Dim pathPDF As String targetName = Selection.Hyperlinks(1).Name parts = Split(targetName, "page=") pageNumber = parts(1) pathPDF = Selection.Hyperlinks(1).Address Call OpenPagePDF(pathPDF, pageNumber) End Sub Public Function OpenPagePDF(sMyPDFPath As String, iMyPageNumber As Integer) Dim RtnCode, AdobePath As String AdobePath = " C:\Program Files\SumatraPDF\SumatraPDF.exe" RtnCode = Shell(AdobePath & " /a " & Chr(34) & "page=" & iMyPageNumber & "=OpenActions" & Chr(34) & " " & Chr(34) & sMyPDFPath & Chr(34), 1) End Function I thought maybe this was just a problem with Sumatra PDF, but when I change the executable to point to Foxit, the desired PDF doesn’t even open at all when I execute the macro — Foxit just opens with a blank background. Does anyone have any ideas on how to make this a working macro? Thank you so much in advance! |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
LOUF | Word VBA | 1 | 12-07-2015 06:47 PM |
![]() |
pizzaman1 | Word VBA | 6 | 11-14-2014 11:25 PM |
Macro Needed to bold specific lines and Macro to turn into CSV | anewteacher | Word VBA | 1 | 05-28-2014 03:59 PM |
can I run a macro when I open a specific doc. | shreked | Word | 8 | 01-12-2012 03:36 AM |
Why isn't my hyperlinked word text hyperlinked when I convert it to pdf? | Obisco | Word | 0 | 12-10-2010 01:58 PM |