VBA表单mailto超链接输出到客户端问题

时间:2011-07-26 20:01:09

标签: email vba hyperlink mailto

我有一个表格在Excel工作表中查找电子邮件地址,可以很好地创建mailto超链接。他们看起来像这样......

enter image description here

但我想展示这个人的真实姓名,就像这样,我有可用的字符串......

enter image description here

我的问题是,这是否可以通过链接的构建方式完成,或者这是电子邮件客户端通过匹配地址簿进行的操作? 我更喜欢训练地址簿,而不是仅创建电子邮件地址。

另外这里有我的样本

Link = "mailto:" & EmpForm.Label10
whoTo = EmpForm.TextBox3 'which I want to use in the TO:whoever
ActiveWorkbook.FollowHyperlink Address:=Link, NewWindow:=True

2 个答案:

答案 0 :(得分:1)

不是在Excel中跟踪链接,而是删除此部分:

ActiveWorkbook.FollowHyperlink Address:=Link, NewWindow:=True

您可以从Excel创建邮件。因此,您可以设置所需的参数 以下是代码示例(找到here):

' requires a reference to the Microsoft Outlook 8.0 Object Library    
Sub SendAnEmailWithOutlook()
' creates and sends a new e-mail message with Outlook
Dim OLF As Outlook.MAPIFolder, olMailItem As Outlook.MailItem
Dim ToContact As Outlook.Recipient
    Set OLF = GetObject("", _
        "Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
    Set olMailItem = OLF.Items.Add ' creates a new e-mail message
    With olMailItem
        .Subject = "Subject for the new e-mail message" ' message subject
        Set ToContact = .Recipients.Add("name@domain.com") ' add a recipient
        Set ToContact = .Recipients.Add("name@company.com") ' add a recipient
        ToContact.Type = olCC ' set latest recipient as CC
        Set ToContact = .Recipients.Add("name@org.net") ' add a recipient
        ToContact.Type = olBCC ' set latest recipient as BCC
        .Body = "This is the message text" & Chr(13) 
        ' the message text with a line break
        .Attachments.Add "C:\FolderName\Filename.txt", olByValue, , _
            "Attachment" ' insert attachment
'        .Attachments.Add "C:\FolderName\Filename.txt", olByReference, , _
             "Shortcut to Attachment" ' insert shortcut
'        .Attachments.Add "C:\FolderName\Filename.txt", olEmbeddedItem, , _
             "Embedded Attachment" ' embedded attachment
'        .Attachments.Add "C:\FolderName\Filename.txt", olOLE, , _
             "OLE Attachment" ' OLE attachment
        .OriginatorDeliveryReportRequested = True ' delivery confirmation
        .ReadReceiptRequested = True ' read confirmation
        '.Save ' saves the message for later editing
        .Send ' sends the e-mail message (puts it in the Outbox)
    End With
    Set ToContact = Nothing
    Set olMailItem = Nothing
    Set OLF = Nothing
End Sub

要创建收件人字段,您可以使用:

arrTo = Split(whoTo,"@")
whoTo = UCase(arrTo[0]) & " " & UCase(arrTo[1]) & "<" & whoTo & ">"

答案 1 :(得分:0)

如果您邮寄的电子邮件地址存在于其地址簿中,则Outlook新邮件窗口将显示您的姓名,否则将显示完整的电子邮件地址。