Hi I found this VBA code that opens PDF hyperlinks and prints them
It works perfectly
I was wondering if it can be changed to instead of printing it to the printer it saves it to PDF creating a pdf file of the hyperlinks.
So basically I want to put hyperlinks to pdf documents that needs to print to pdf resulting in al the hyperlinks being merged into one new pdf document
It works perfectly
I was wondering if it can be changed to instead of printing it to the printer it saves it to PDF creating a pdf file of the hyperlinks.
So basically I want to put hyperlinks to pdf documents that needs to print to pdf resulting in al the hyperlinks being merged into one new pdf document
VBA Code:
Public Sub Print_Hyperlink_PDFs()
Dim r As Long
Dim PDFfile As String
With ActiveSheet
For r = 2 To .Cells(.Rows.Count, "B").End(xlUp).Row
PDFfile = GetHyperlinkLocation(.Cells(r, "B"))
If PDFfile <> "" Then
Print_PDF PDFfile
Else
MsgBox "Link location not found for cell " & .Cells(r, "B").Address, vbExclamation
End If
Next
End With
End Sub
Private Function GetHyperlinkLocation(cell As Range) As String
Dim p1 As Long, p2 As Long
With cell.Item(1, 1)
If .Hyperlinks.Count = 1 Then
GetHyperlinkLocation = .Hyperlinks(1).Address
Else
p1 = InStr(1, .Formula, "HYPERLINK(", vbTextCompare)
If p1 > 0 Then
p1 = p1 + Len("HYPERLINK(")
p2 = InStr(p1, .Formula, ",")
If p2 > 0 Then
GetHyperlinkLocation = Evaluate(Mid(.Formula, p1, p2 - p1))
End If
Else
GetHyperlinkLocation = ""
End If
End If
End With
End Function
Private Sub Print_PDF(PDFfullName As String)
CreateObject("Shell.Application").Namespace(Left(PDFfullName, InStrRev(PDFfullName, "\"))).Items.Item(Mid(PDFfullName, InStrRev(PDFfullName, "\") + 1)).InvokeVerb "Print"
End Sub
Last edited by a moderator: