ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,832
- Office Version
- 2007
- Platform
- Windows
I have a worksheet with the supplied code on a command button.
The user would select cell G3 & click the command button to apply a hyperlink to the invoice of which is a pdf.
So i am working on a different worksheet where once all values have been entered into the relevant cells the user prints off an invoice.
The invoice is saved in a folder & is a pdf.
It is now i wish to apply the hyperlink on that other worksheet for the the invoice that was just saved & printed.
It just saves the user printing the invoice then having to watch the other sheet open, have thehyperlink applied then worksheet closed
To the bring him back to the worksheet he is workin on.
I would basically be,select cell G3 Apply the hyperlink to the pdf & job done.
The messages in the below code like HYPERLINK WAS SUCCESSFULL will be removed to minimise the code.
The user would select cell G3 & click the command button to apply a hyperlink to the invoice of which is a pdf.
So i am working on a different worksheet where once all values have been entered into the relevant cells the user prints off an invoice.
The invoice is saved in a folder & is a pdf.
It is now i wish to apply the hyperlink on that other worksheet for the the invoice that was just saved & printed.
It just saves the user printing the invoice then having to watch the other sheet open, have thehyperlink applied then worksheet closed
To the bring him back to the worksheet he is workin on.
I would basically be,select cell G3 Apply the hyperlink to the pdf & job done.
The messages in the below code like HYPERLINK WAS SUCCESSFULL will be removed to minimise the code.
VBA Code:
Private Sub HyperlinkInvoice_Click()
Const FILE_PATH As String = "C:\Users\Ian\Desktop\REMOTES ETC\DR\DR COPY INVOICES\"
If ActiveCell.Column = Columns("G").Column Then
If Len(Dir(FILE_PATH & ActiveCell.Value & ".pdf")) Then
ActiveCell.Hyperlinks.Add Anchor:=ActiveCell, Address:=FILE_PATH & ActiveCell.Value & ".pdf"
With ActiveCell
.Font.Size = 16
.Font.Bold = True
End With
MsgBox "HYPERLINK WAS SUCCESSFUL.", vbExclamation, "HYPERLINKING THE INVOICE NUMBER"
Else
ActiveCell.Hyperlinks.Delete
MsgBox (FILE_PATH & ActiveCell.Value & ".pdf" & vbNewLine & vbNewLine & "FILE IS NOT IN FOLDER SPECIFIED, PLEASE CHECK PATH IS CORRECT"), vbCritical
End If
Else
MsgBox "PLEASE SELECT AN INVOICE NUMBER.", vbExclamation, "HYPERLINKING THE INVOICE NUMBER"
End If
End Sub