【问题标题】:Insert Hyperlink in Outlook body在 Outlook 正文中插入超链接
【发布时间】:2016-06-23 03:35:13
【问题描述】:

所以我正在尝试创建一个代码来加快在 Outlook 中插入超链接。

我想拥有它,这样如果我已经复制了一个路径,我可以进入并键入 Ctrl W,它会在此处插入该单词的超链接。我对代码的尝试是:

Sub InsertHyperlink()
'
'
'
On Error Resume Next
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
    "U:\plot.log", _
    SubAddress:="", ScreenTip:="", TextToDisplay:="here"
End Sub

我在如何更新我的代码以便在 Outlook 中工作(我在 Word 中对其进行编程)时遇到问题,因此“U:\plot.log”实际上是复制的路径(而不是复制的路径)我录制了宏)。

有人有什么建议吗?

【问题讨论】:

  • 对不起,我忘了点击接受。再次感谢您的帮助!

标签: vba outlook hyperlink outlook-2010


【解决方案1】:

设置对 Word 对象库的引用

Tools > References > add Word object Library

Option Explicit
Sub Add_Hyperlinks()
    Dim olNameSpace As Outlook.NameSpace
    Dim wDoc As Word.Document
    Dim rngSel As Word.Selection

    If Application.ActiveInspector.EditorType = olEditorWord Then
        Set wDoc = Application.ActiveInspector.WordEditor ' use WordEditor
        Set olNameSpace = Application.Session
        Set rngSel = wDoc.Windows(1).Selection ' Current selection

        wDoc.Hyperlinks.Add rngSel.Range, _
        Address:="U:\plot.log", TextToDisplay:="Here is the link"
    End If

    Set wDoc = Nothing
    Set olNameSpace = Nothing

End Sub

【讨论】:

    【解决方案2】:

    非常感谢您的帮助,我真的很感激!所以我对你的代码做了一点改动,试图让它粘贴剪贴板上的任何内容。

    我的新代码如下。我需要添加任何错误捕获吗?另外,明确的选项究竟做了什么?

    Option Explicit
    Sub Add_Hyperlinks()
       Dim olNameSpace As Outlook.NameSpace
       Dim wDoc As Word.Document
       Dim rngSel As Word.Selection
       Dim DataObj As MSForms.DataObject
       Set DataObj = New MSForms.DataObject
       DataObj.GetFromClipboard
    If Application.ActiveInspector.EditorType = olEditorWord Then
        Set wDoc = Application.ActiveInspector.WordEditor ' use WordEditor
        Set olNameSpace = Application.Session
        Set rngSel = wDoc.Windows(1).Selection ' Current selection
        wDoc.Hyperlinks.Add rngSel.Range, _
        Address:=DataObj.GetText(1), TextToDisplay:="here"
    End If
    Set wDoc = Nothing
    Set olNameSpace = Nothing
    End Sub
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-17
    • 2018-03-25
    • 1970-01-01
    • 2017-05-03
    • 2011-10-15
    • 1970-01-01
    相关资源
    最近更新 更多