Excel 使用Word VBA在Outlook正文中插入超链接

Excel 使用Word VBA在Outlook正文中插入超链接,excel,vba,outlook,hyperlink,ms-word,Excel,Vba,Outlook,Hyperlink,Ms Word,如何将超链接添加到电子邮件的最后一部分并与文本相结合 这一定是我这一段的最后一句话了 “如果您有疑问/澄清,请联系服务中心的服务管理人员_Management@xyz.com" “服务”一词_Management@xyz.com“必须有超链接 'Reference to Word Object Library required objSel.EndKey Unit:=wdStory ' Reference to Word Object Library not required objSel.

如何将超链接添加到电子邮件的最后一部分并与文本相结合

这一定是我这一段的最后一句话了

“如果您有疑问/澄清,请联系服务中心的服务管理人员_Management@xyz.com"

“服务”一词_Management@xyz.com“必须有超链接

'Reference to Word Object Library required
 objSel.EndKey Unit:=wdStory

' Reference to Word Object Library not required
objSel.EndKey Unit:=6
我尝试从以下位置编辑代码:

wd.Hyperlinks.Add wd.Range(wd.Paragraphs.Count), _
  "mailto:Service_Management@xyz.com" & "Service_Management@xyz.com"
问题是电子邮件正文的底部变成了链接。邮件正文没有显示文本。如何正确声明链接,使其不会影响范围的其他部分

 Sub AUTOMAIL()

    Dim ol As Object 'Outlook.Application
    Dim olEmail As Object 'Outlook.MailItem
    Dim olInsp As Object 'Outlook.Inspector
    Dim wd As Object 'Word.Document
    Dim rCol As Collection, r As Range, i As Integer
    Dim Table1 As Collection

    Dim ETo As String
    Dim CTo As String

    ETo = Join(Application.Transpose(Worksheets("Data Entry").Range("AD5:AD100").Value), ";")
    CTo = Join(Application.Transpose(Worksheets("Data Entry").Range("AI5:AI15").Value), ";")

     '/* if outlook is running use GO, create otherwise */
    Set ol = GetObject(Class:="Outlook.Application")
    Set olEmail = ol.CreateItem(0) 'olMailItem

    Set Table1 = New Collection

    With Table1
        .Add Sheet14.Range("A1:O20")
    End With

    Set rCol = New Collection
    With rCol   
        .Add Sheet11.Range("a1:i1", "a6:i20")
        .Add Sheet10.Range("a1:i1", "A6:I20")
        .Add Sheet9.Range("A1:J18")
    End With

    With olEmail
        .To = ETo
        .CC = CTo
        .Subject = "Step+ Volume Tracker, Data Entry/Workflow Ageing Report and Rejection Report | " & Format(Date, "MMMM dd, yyyy") & " | 9:15AM"

        '/* bonus basic html */
        .HTMLBody = "<html><body style=""font-family:calibri"">" & _
                    "<p><b>Dear All,</b><br><br> Please see below summary of invoices and links to the <b>Volume Tracker</b> and <b>Ageing Report</b> (Data Entry and Workflow)." & _
                    "</p></body></html>"

           Set olInsp = .GetInspector
           If olInsp.EditorType = 4 Then 'olEditorWord
               Set wd = olInsp.WordEditor
               For i = 1 To Table1.Count '/* iterate all ranges */
                   Set r = Table1.Item(i): r.Copy
                   wd.Range.insertparagraphafter
                   wd.Paragraphs(wd.Paragraphs.Count).Range.PasteAndFormat 16
                   '16 - wdFormatOriginalFormatting
            Next
        End If
        wd.Paragraphs(wd.Paragraphs.Count).Range.Text = Chr(11) & "Please click on this link to view the details:"

        Set olInsp = .GetInspector
        If olInsp.EditorType = 4 Then 'olEditorWord
            Set wd = olInsp.WordEditor
            For i = 1 To rCol.Count '/* iterate all ranges */
                Set r = rCol.Item(i): r.Copy
                wd.Range.insertparagraphafter
                wd.Paragraphs(wd.Paragraphs.Count).Range.PasteAndFormat 16
                '16 - wdFormatOriginalFormatting
            Next
        End If

        wd.Paragraphs(wd.Paragraphs.Count).Range.Text = Chr(11) & "Please click on this link to view the details:" & vbCrLf & "Those who are encountering problems accessing the Sharepoint site, please refer to attachment for Data Entry and Workflow Report. " & Chr(11) & "Please note though that the file has been truncated, complete details of the report are available in the links indicated above." & Chr(11) & Chr(11) & "Should you have questions/clarifications, kindly reach out to Service Management at"
        wd.Range(wd.Paragraphs(wd.Paragraphs.Count).Range.Characters(98).Start, _
        wd.Paragraphs(wd.Paragraphs.Count).Range.Characters(128).End).Font.Bold = True

        wd.Range.Hyperlinks.Add Anchor:=wd.Range, _
        Address:="mailto:Service_Management@xyz.com"
        wd.Range.Font.Size = 10
        .Display

    End With

End Sub
Sub AUTOMAIL()
Dim ol作为对象的Outlook.Application
将邮件作为对象“Outlook.MailItem”发送
将olInsp设置为对象的Outlook.Inspector
将wd设置为对象的Word.Document
Dim rCol作为集合,r作为范围,i作为整数
将表1作为集合
将ETo设置为字符串
作为字符串的Dim CTo
ETo=Join(Application.Transpose(工作表(“数据输入”).Range(“AD5:AD100”).Value),“;”)
CTo=Join(Application.Transpose(工作表(“数据输入”).Range(“AI5:AI15”).Value),“;”)
“/*如果outlook正在运行,请使用GO,否则请创建*/
Set ol=GetObject(类:=“Outlook.Application”)
设置olEmail=ol.CreateItem(0)'olMailItem
Set Table1=新集合
见表1
.添加活页14.范围(“A1:O20”)
以
Set rCol=新集合
使用rCol
添加活页11.范围(“a1:i1”、“a6:i20”)
.添加表10.范围(“a1:i1”、“A6:I20”)
.添加表9.范围(“A1:J18”)
以
用电子邮件
.To=ETo
.CC=CTo
.Subject=“Step+卷跟踪器、数据输入/工作流老化报告和拒绝报告”&Format(日期:年月日)和“上午9:15”
'/*奖金基本html*/
.HTMLBody=”“&_
“尊敬的各位,

请参见下面的发票摘要以及卷跟踪器和账龄报告链接(数据输入和工作流程)。”_ “

” 设置olInsp=.GetInspector 如果olInsp.EditorType=4,则“olEditorWord” Set wd=olInsp.WordEditor 对于表1中的i=1。计数“/*迭代所有范围*/ 集合r=表1.项目(i):r.副本 wd.Range.insertparagraphafter wd.段落(wd.段落.计数).范围.粘贴和格式16 '16-WDFormat原始格式设置 下一个 如果结束 wd.parations(wd.parations.Count).Range.Text=Chr(11)&“请单击此链接查看详细信息:” 设置olInsp=.GetInspector 如果olInsp.EditorType=4,则“olEditorWord” Set wd=olInsp.WordEditor 对于i=1到rCol.Count'/*迭代所有范围*/ 设置r=rCol.项目(i):r.副本 wd.Range.insertparagraphafter wd.段落(wd.段落.计数).范围.粘贴和格式16 '16-WDFormat原始格式设置 下一个 如果结束 wd.parations(wd.parations.Count).Range.Text=Chr(11)和“请单击此链接查看详细信息:&vbCrLf&”访问Sharepoint网站时遇到问题的用户,请参阅附件以获取数据输入和工作流报告。&Chr(11)和“请注意,尽管该文件已被截断,但报告的完整详细信息可在上述链接中找到。”&Chr(11)&Chr(11)&“如果您有疑问/澄清,请联系服务管理部门,网址为” wd.Range(wd.parations(wd.parations.Count)).Range.Characters(98).Start_ wd.parations(wd.parations.Count).Range.Characters(128.End).Font.Bold=True wd.Range.Hyperlinks.Add锚点:=wd.Range_ 地址:=“mailto:服务”_Management@xyz.com" wd.Range.Font.Size=10 .展示 以 端接头
将所选内容移动到邮件末尾,然后插入超链接

'Reference to Word Object Library required
 objSel.EndKey Unit:=wdStory

' Reference to Word Object Library not required
objSel.EndKey Unit:=6
这是一个比您问题中的代码噪音更小的示例

Sub AUTOMAIL()

    Dim ol As Object 'Outlook.Application
    Dim olEmail As Object 'Outlook.MailItem
    Dim olInsp As Object 'Outlook.Inspector
    Dim wd As Object 'Word.Document

     '/* if outlook is running use GO, create otherwise */
    Set ol = GetObject(Class:="Outlook.Application")
    Set olEmail = ol.CreateItem(0) 'olMailItem

    With olEmail

        '/* bonus basic html */
        .HTMLBody = "<html><body style=""font-family:calibri"">" & _
                    "<p><b>Dear All,</b><br><br> Please see below summary of invoices and links to the <b>Volume Tracker</b> and <b>Ageing Report</b> (Data Entry and Workflow)." & _
                    "</p></body></html>"

        Set olInsp = .GetInspector
        If olInsp.EditorType = 4 Then 'olEditorWord
            Set wd = olInsp.WordEditor
            wd.Range.InsertParagraphAfter
        End If

        wd.Paragraphs(wd.Paragraphs.Count).Range.Text = Chr(11) & "Please click on this link to view the details:" & vbCrLf & "Those who are encountering problems accessing the Sharepoint site, please refer to attachment for Data Entry and Workflow Report. " & Chr(11) & "Please note though that the file has been truncated, complete details of the report are available in the links indicated above." & Chr(11) & Chr(11) & "Should you have questions/clarifications, kindly reach out to Service Management at"

        wd.Range.InsertParagraphAfter

        Dim objSel As Object
        Set objSel = wd.Windows(1).Selection

        'Reference to Word Object Library required
        'objSel.EndKey Unit:=wdStory

        ' Reference to Word Object Library not required
        objSel.EndKey Unit:=6

        wd.Range.Hyperlinks.Add Anchor:=objSel.Range, _
          Address:="mailto:Service_Management@xyz.com"

        .Display

    End With

End Sub
Sub AUTOMAIL()
Dim ol作为对象的Outlook.Application
将邮件作为对象“Outlook.MailItem”发送
将olInsp设置为对象的Outlook.Inspector
将wd设置为对象的Word.Document
“/*如果outlook正在运行,请使用GO,否则请创建*/
Set ol=GetObject(类:=“Outlook.Application”)
设置olEmail=ol.CreateItem(0)'olMailItem
用电子邮件
'/*奖金基本html*/
.HTMLBody=”“&_
“尊敬的各位,

请参见下面的发票摘要以及卷跟踪器和账龄报告链接(数据输入和工作流程)。”_ “

” 设置olInsp=.GetInspector 如果olInsp.EditorType=4,则“olEditorWord” Set wd=olInsp.WordEditor wd.Range.InsertParagraphAfter 如果结束 wd.parations(wd.parations.Count).Range.Text=Chr(11)&“请单击此链接查看详细信息:”&vbCrLf&“如果访问Sharepoint网站时遇到问题,请参阅附件以获取数据输入和工作流报告。”。&Chr(11)&“请注意,尽管文件已被截断,但报告的完整详细信息可在上述链接中找到。”&Chr(11)&Chr(11)&“如果您有疑问/澄清,请联系服务管理部门,网址为” wd.Range.InsertParagraphAfter 作为对象的Dim objSel 设置objSel=wd.Windows(1).Selection '需要对Word对象库的引用 'objSel.EndKey单位:=wdStory '不需要对Word对象库的引用 objSel.EndKey单位:=6 wd.Range.Hyperlinks.Add锚点:=objSel.Range_ 地址:=“mailto:服务”_Management@xyz.com" .展示 以 端接头
在这个问题上我真的需要帮助,请帮助。我通常用简单的旧html添加它:
“联系。”
我已经尝试过帮你解决同样的问题,你现在显然已经删除了。如果你