Outlook to Excel hyperlink issue

坚强是说给别人听的谎言 提交于 2020-01-05 02:58:55

问题


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


回答1:


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"


来源:https://stackoverflow.com/questions/19300311/outlook-to-excel-hyperlink-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!