charmain49
New Member
- Joined
- Oct 11, 2017
- Messages
- 1
Hi,
I have set up my own stock control with Purchase orders. Using a VBA I save the PO to a register and also save a pdf copy to another folder. i would like to open the PDF from the Register using a hyperlink (this i have completed), but it only opens the folder with the PO's listed. How can I get it to open the specific PDF linked with the number. Have i done something wrong in the code.
Sub AddHyperlinks()
Dim lastRow As Long
Dim myPath As String, fileName As String
myPath = "C:\shared folder\purchases\orders" 'SET TO WHERE THE FILES ARE LOCATED
lastRow = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To lastRow
fileName = myPath & Range("A" & i).Value & "*.pdf"
If Len(Dir(myPath)) <> 0 Then 'IF THE FILE EXISTS THEN
ActiveSheet.Hyperlinks.Add Range("A" & i), myPath
End If
Next
End Sub
I have set up my own stock control with Purchase orders. Using a VBA I save the PO to a register and also save a pdf copy to another folder. i would like to open the PDF from the Register using a hyperlink (this i have completed), but it only opens the folder with the PO's listed. How can I get it to open the specific PDF linked with the number. Have i done something wrong in the code.
Sub AddHyperlinks()
Dim lastRow As Long
Dim myPath As String, fileName As String
myPath = "C:\shared folder\purchases\orders" 'SET TO WHERE THE FILES ARE LOCATED
lastRow = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To lastRow
fileName = myPath & Range("A" & i).Value & "*.pdf"
If Len(Dir(myPath)) <> 0 Then 'IF THE FILE EXISTS THEN
ActiveSheet.Hyperlinks.Add Range("A" & i), myPath
End If
Next
End Sub