简体   繁体   English

Outlook 到 Excel 超链接问题

[英]Outlook to Excel hyperlink issue

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.作为 Outlook 宏的一部分,我希望使用指向文档的超链接更新 excel 中的单元格。

'~~> 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!出于某种原因,它只是调试,代码在 excel 中运行良好,所以我一定遗漏了一些东西,请帮忙!

Cheers, Dom干杯,多姆

Since you are latebinding with Excel, Outlook doesn't understand what is Selection由于您使用 Excel 进行后期绑定,因此 Outlook 不了解什么是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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM