You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Outlook中调用Word.Hyperlink对象无法获取TextToDisplay属性值

问题:Outlook中通过Word.Hyperlink无法获取超链接显示文本

我尝试在Outlook里调用Word.Hyperlink对象,获取邮件内嵌超链接的属性,但没法返回人类可读的显示文本。因为找不到Outlook.Hyperlink对象(已确认在Outlook中添加了Word引用),所以改用Word对象模型实现。

以下是我的VB代码:

Public Sub SaveLinks()

Dim objOL As Outlook.Application
Dim objMail As Outlook.MailItem
Dim objAttachments As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim objMaildocument As Word.Document
Dim objHyperlink As Word.Hyperlink

' Initiate an Outlook Application object.
Set objOL = CreateObject("Outlook.Application")

' Get the collection of selected objects.
Set objSelection = objOL.ActiveExplorer.Selection

If objSelection.Count > 0 Then

    For Each objMail In objSelection
        Set objMaildocument = objMail.GetInspector.WordEditor
        If objMaildocument.Hyperlinks.Count > 0 Then
            For Each objHyperlink In objMaildocument.Hyperlinks
                MsgBox (objHyperlink.Address)
                MsgBox (objHyperlink.Name)
                MsgBox (objHyperlink.TextToDisplay)
            Next
        End If
    Next
End If

ExitSub:

Set objAttachments = Nothing
Set objHyperlink = Nothing
Set objMail = Nothing
Set objSelection = Nothing
Set objOL = Nothing

End Sub

运行代码后,能获取到超链接的地址等属性,但TextToDisplay属性始终为空,我期望它返回邮件中显示的超链接文本。另外,尽管文档标注该属性为读写属性,但尝试给它赋值时,会触发“Runtime error '4198' Command Failed”错误。

内容的提问来源于stack exchange,提问作者Chris Ayers

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 16:34:59