【问题标题】:Add hyperlink to Outlook email which goes to row number when opening Excel spreadsheet在打开 Excel 电子表格时添加指向行号的 Outlook 电子邮件的超链接
【发布时间】:2016-01-18 22:27:18
【问题描述】:

我有一个使用 VBA 发送电子邮件的 Excel 电子表格:

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

strbody = "This is email text, click the link <a href='C:\test.xlsm & Range("F" & ActiveCell.Row).Address'></a>"

On Error Resume Next

With OutMail
    .To = "####"
    .CC = ""
    .BCC = ""
    .Subject = "Sales Tracker: A New Task has been added to the tracker"
    .HTMLBody = strbody & strbody2 & strbody3 & strbody4
    .Send 'displays outlook email
    'Application.SendKeys "%s" 'presses send as a send key
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing 

当用户点击活动行中的特定单元格时发送电子邮件。

我在电子邮件中包含带有超链接的 Excel 电子表格。

现在我想添加到超链接以包含用户单击的行的单元格引用

这个想法是点击超链接时会打开电子表格,并将用户带到链接所指的行并突出显示它。

【问题讨论】:

    标签: excel vba outlook


    【解决方案1】:

    您在链接中缺少工作表的引用(尽管我不确定这是否足够),所以试试这样的:

    href='[C:\test.xlsm]" & ActiveSheet.Name & "!" & Range("F" & ActiveCell.Row).Address & "'></a>"
    

    匹配这种格式:

    href='[C:\test.xlsm]SheetName!A1'
    

    更重要的是,您忘记正确关闭引号,所以这里是:

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    
    strbody = "This is email text, click the link <a href='[C:\test.xlsm]" & _
                ActiveSheet.Name & "!" & Range("F" & ActiveCell.Row).Address & "'></a>"
    
    On Error Resume Next
    
    
    With OutMail
        .To = "####"
        .CC = ""
        .BCC = ""
        .Subject = "Sales Tracker: A New Task has been added to the tracker"
        .HTMLBody = strbody & strbody2 & strbody3 & strbody4
        .Send 'displays outlook email
        'Application.SendKeys "%s" 'presses send as a send key
    End With
    On Error GoTo 0
    
    Set OutMail = Nothing
    Set OutApp = Nothing
    

    【讨论】:

      【解决方案2】:

      我不确定是否可以使用超链接来实现,很可能不会。我唯一想到的是将 Worksheet_Activate() 事件添加到您要附加的电子表格中,并指向您希望的范围,但不是超链接。

      【讨论】:

        猜你喜欢
        • 2017-04-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-25
        • 2018-03-11
        • 1970-01-01
        • 1970-01-01
        • 2015-07-17
        相关资源
        最近更新 更多