I have a part number in a cell and want to add a link to the cell next to it. I do something similar for long lists of parts and it works fine, but this method does not. Is it because I'm using .Cells(AciveCell.Address) ??
Here's the code I'm using:
I'm sure I'm going about this wrong by activating the cell instead of referencing it, but I'm not sure how to extract the reference from the offset function. But I can't fix that until I fix the error message.
Here's the code I'm using:
Code:
Sub AddOneURL()
Dim cellPointer As String
Dim sWS As String
Dim MyFile As String
Const cPath = "N:\pdfs\engineering\"
sWS = ActiveSheet.Name
cellPointer = ActiveCell.Value
ActiveCell.Offset(0, 1).Activate
MyFile = Dir(cPath & Left(cellPointer, 7) & "*.pdf")
If MyFile <> "" Then
Worksheets(sWS).Cells([COLOR=red]ActiveCell.Address[/COLOR]).Hyperlinks.add _
Anchor:=Worksheets(sWS).Cells([COLOR=red]ActiveCell.Address[/COLOR]), _
Address:=cPath & MyFile, TextToDisplay:="PDF"
End If
End Sub
I'm sure I'm going about this wrong by activating the cell instead of referencing it, but I'm not sure how to extract the reference from the offset function. But I can't fix that until I fix the error message.