Reputation: 61
Hoping you can help me understand what i am doing wrong here.
As part of my Outlook macro, i am looking to update a cell in excel with a hyperlink to a document.
'~~> Excel variables
Dim oXLApp As Object, oXLwb As Object, oXLws As Object
'~~> Establish an EXCEL application object
On Error Resume Next
Set oXLApp = GetObject(, "Excel.Application")
'~~> If not found then create new instance
If Err.Number <> 0 Then
Set oXLApp = CreateObject("Excel.Application")
End If
Err.Clear
On Error GoTo 0
'~~> Show Excel
oXLApp.Visible = True
'~~> Open the relevant file
Set oXLwb = oXLApp.Workbooks.Open("V:\Dir\filename.xls")
'~~> Set the relevant output sheet. Change as applicable
Set oXLws = oXLwb.Sheets("Outstanding")
oXLws.Range("R11").Select
oXLws.Range("R11").Hyperlinks.Add Anchor:=Selection, Address:= _
"V:\Dir\" & emailsub & ".msg" _
, TextToDisplay:="Here"
For some reason it just debugs, the code works fine from excel, so i must be missing something, please help!
Cheers, Dom
Upvotes: 2
Views: 833
Reputation: 149325
Since you are latebinding with Excel, Outlook doesn't understand what is Selection
Change these lines
oXLws.Range("R11").Select
oXLws.Range("R11").Hyperlinks.Add Anchor:=Selection, Address:= _
"V:\Dir\" & emailsub & ".msg", TextToDisplay:="Here"
To
oXLws.Range("R11").Hyperlinks.Add Anchor:=oXLws.Range("R11"), Address:= _
"V:\Dir\" & emailsub & ".msg", TextToDisplay:="Here"
Upvotes: 3