对象变量或未设置块变量(错误91)

 xinlang138438 发布于 2023-02-09 09:35

我有以下代码:

Sub AddSources()
    Dim pubPage As Page
    Dim pubShape As Shape
    Dim hprlink As Hyperlink
    Dim origAddress() As String
    Dim exportFileName As String
    exportFileName = "TestResume"
    Dim linkSource As String
    linkSource = "TestSource2"
    Dim hyperLinkText As TextRange



    For Each pubPage In ActiveDocument.Pages
        For Each pubShape In pubPage.Shapes
            If pubShape.Type = pbTextFrame Then
                For Each hprlink In pubShape.TextFrame.TextRange.Hyperlinks
                    If InStr(hprlink.Address, "http://bleaney.ca") > 0 Then
                        hyperLinkText = hprlink.Range
                        origAddress = Split(hprlink.Address, "?source=")
                        hprlink.Address = origAddress(0) + "?source=" + linkSource
                        hprlink.Range = hyperLinkText
                    End If
                Next hprlink
            End If
        Next pubShape
    Next pubPage
    ThisDocument.ExportAsFixedFormat pbFixedFormatTypePDF, "C:\" + exportFileName + ".pdf"
End Sub

我收到了"对象变量或未设置块变量(错误91)"错误hyperLinkText = hprlink.Range.当我调试时,我可以看到它hprlink.Range确实有价值.我有什么想法我做错了吗?

1 个回答
  • 正如我在评论中所写,问题的解决方案是编写以下内容:

    Set hyperLinkText = hprlink.Range
    

    Set需要因为TextRange是一个类,所以hyperLinkText是一个对象; 因此,如果要分配它,则需要指向所需的实际对象.

    2023-02-09 09:39 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有