VBA error: Object doesn't support this action (Error 445)

VBA error: Object doesn't support this action (Error 445)

每当我启动 Microsoft Word 并第一次使用以下宏时,我都会收到错误消息:

Object doesn't support this action (Error 445)

如果我重新启动 makro,错误就会消失。

Sub SelectedURLtoHyperlink()

    Dim MyData As DataObject
    Dim strClip As String

    Set MyData = New DataObject
    Selection.Copy
    MyData.GetFromClipboard
    strClip = MyData.GetText

    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:=strClip, SubAddress:="", ScreenTip:="", TextToDisplay:=Selection.Range 

End sub

显然错误在行 Set MyData = New DataObject.

有人知道为什么会出现此错误吗?

完全没有必要使用剪贴板从所选文本创建超链接。

Sub SelectedURLtoHyperlink()

    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:=Selection.Text, SubAddress:="", ScreenTip:="", TextToDisplay:=Selection.Text

End Sub

我无法重现您的问题,所以这有点摸不着头脑。尝试替换

Set MyData = New DataObject

Set MyData = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")

在新 Windows 中创建 DataObject 对象存在一些问题。