首页 文章

从excel发送outlook电子邮件并在电子邮件中添加超链接,在打开电子表格时会转到行号

提问于
浏览
1

我有一个excel电子表格,使用vba发送电子邮件:

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电子表格,其中包含超链接,但现在我想在发送电子邮件时 be able to add something to the hyperlink which will allow me to include the cell reference of the row the user click on .

这样的想法是打开时的超链接将打开电子表格,并将用户带到链接引用的行并突出显示它 .

请有人告诉我该怎么做?提前致谢

2 回答

  • 0

    您缺少链接中工作表的引用(即使我不确定这是否足够),请尝试这样的方法:

    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
    
  • 1

    我不确定是否可以用超链接来做,很可能不是 . 我想到的只是将Worksheet_Activate()事件添加到您附加的电子表格中,并指向您希望的范围,但不包含超链接 .

相关问题