Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 在Outlook正文中插入超链接_Vba_Outlook_Hyperlink_Outlook 2010 - Fatal编程技术网

Vba 在Outlook正文中插入超链接

Vba 在Outlook正文中插入超链接,vba,outlook,hyperlink,outlook-2010,Vba,Outlook,Hyperlink,Outlook 2010,因此,我试图创建一个代码,以加快在Outlook中插入超链接 我正在尝试使用它,这样,如果我已经复制了一个路径,我就可以进入并键入Ctrl W,它将在此处插入该单词的超链接。我对代码的尝试是: Sub InsertHyperlink() ' ' ' On Error Resume Next ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _ "U:\plot.log", _ SubAddress:=

因此,我试图创建一个代码,以加快在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”实际上是复制的路径(而不是录制宏时复制的路径)方面遇到问题


有人有什么建议吗?

设置对Word对象库的引用

工具>参考>添加Word对象库

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

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

我的新代码如下。我需要添加错误捕获吗?另外,显式选项到底做了什么

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

对不起,我忘了点击“接受”。再次感谢你的帮助!我认为您不需要错误捕获-另请参见