用于在Outlook中插入文本和超链接的VBA

问题描述 投票:0回答:1

我有以下代码,并希望在变量显示中插入超链接:

xRecipName = Split("https://www.alumbra.com.br/pesquisa.php?x=" & xRecipAddress)(0)


Sub InsertRecipientNamesToBody()
Dim xMailItem As Outlook.MailItem
Dim xRecipient As Outlook.Recipient
Dim xRecipAddress, xRecipNames, xRecipName, xFilterAddr As String
Dim xItems As Outlook.Items
Dim i As Integer
Dim xFoundContact As Outlook.ContactItem
Dim xDoc As Word.Document
On Error Resume Next
Set xMailItem = Outlook.ActiveInspector.CurrentItem
xMailItem.Recipients.ResolveAll
For Each xRecipient In xMailItem.Recipients
    xRecipAddress = xRecipient.Address
    MsgBox (xRecipient.Address)

    Set xItems = Application.Session.GetDefaultFolder(olFolderContacts).Items
    For i = 1 To 3
        xFilterAddr = "[Email" & i & "Address] = " & xRecipAddress

        If Not (xFoundContact Is Nothing) Then
           xRecipNames = xRecipNames & xFoundContact.FullName & Chr(10)
           Exit For
        End If
    Next

       xRecipName = Split("https://www.alumbra.com.br/pesquisa.php?x=" & xRecipAddress)(0)
       xRecipNames = xRecipNames & xRecipName & Chr(10)

Next
Set xDoc = xMailItem.GetInspector.WordEditor
xDoc.Content.InsertAfter xRecipNames
Set xMailItem = Nothing
Set xRecipient = Nothing
Set xItems = Nothing
Set xFoundContact = Nothing
End Sub
vba outlook
1个回答
0
投票

谢谢您的帮助。我成功地更改了代码,但现在它正在擦除正文。你能帮我吗?

Sub InsertRecipientNamesToBody()
Dim xMailItem As Outlook.MailItem
Dim xRecipient As Outlook.Recipient
Dim xRecipAddress, xRecipNames, xFilterAddr As String
Dim xRecipName As Outlook.MailItem
Dim xItems As Outlook.Items
Dim i As Integer
Dim xFoundContact As Outlook.ContactItem
Dim xDoc As Word.Document
On Error Resume Next
Set xMailItem = Outlook.ActiveInspector.CurrentItem
xMailItem.Recipients.ResolveAll
For Each xRecipient In xMailItem.Recipients
    xRecipAddress = xRecipient.Address
    
    Set xItems = Application.Session.GetDefaultFolder(olFolderContacts).Items
    For i = 1 To 3
        xFilterAddr = "[Email" & i & "Address] = " & xRecipAddress
        
        
           xRecipNames = xRecipNames & xFoundContact.FullName & Chr(10)
           
        
    Next
    If (xFoundContact Is Nothing) Then
    Set xRecipName = Application.ActiveInspector.CurrentItem
       xRecipName.HTMLBody = ("Para responder a nossa pesquisa de satisfação" & "<a href='https://www.alumbra.com.br/pesquisa.php?x=" & xRecipAddress & "'> Click Aqui</a>")
       
    End If
Next
Set xDoc = xMailItem.GetInspector.WordEditor
xDoc.Content.InsertAfter xRecipNames
Set xMailItem = Nothing
Set xRecipient = Nothing
Set xItems = Nothing
Set xFoundContact = Nothing
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.