VBA Excel GetObject问题-运行时错误91-对象变量或未设置块变量

时间:2018-07-23 14:10:04

标签: excel vba excel-vba object catia

我遇到错误:

  

“运行时错误91:对象变量或未设置块变量”。

调试用MsgBox()突出显示一行:

Sub CATMain()

    Dim xlApp As Excel.Application    
    Set xlApp = VBA.GetObject("", "Excel.Application")    
    Dim exlBook As Excel.Workbook
    Set exlBook = xlApp.ActiveWorkbook    
    MsgBox exlBook.Name

End Sub

怎么了?

3 个答案:

答案 0 :(得分:2)

VBA.GetObject()中的代码中删除Sub TestMe() Dim xlApp As Excel.Application Set xlApp = VBA.GetObject(, "Excel.Application") Dim exlBook As Excel.Workbook Set exlBook = xlApp.ActiveWorkbook MsgBox exlBook.Name End Sub ,它应该可以工作:

GetObject()

MSDN GetObject。这些是req.body的参数:

  • 路径名-可选;变体(String)。包含要检索的对象的文件的完整路径和名称。如果省略路径名,则需要class。

  • 课程可选;变体(String)。表示对象类的字符串。

答案 1 :(得分:0)

添加:

 xlApp.Application.Visible = True

设置后...

您将看到为什么没有activeworkbook.name

由于“”,您打开了一个新实例

答案 2 :(得分:0)

在CATIA vb模块中:

<script type="application/ld+json">
{
    "@context": "http://schema.org",
    "@type": "Article",
    "@id": "#article",
    "name": "‘Female Brethren’: Gender Dynamics in a Newly Integrated Missionary Force, 1898–1915.",
    "author": "McBride, Matthew.",
    "ispartOf": {
        "@id": "#issue",
        "@type": "PublicationIssue",
        "name": "Journal of Mormon History 44, no. 4 (October 2018)",
        "issueNumber": "4",
        "datePublished": "2018",
        "isPartOf": {
            "@id": "#periodical",
            "@type": ["PublicationVolume","Periodical"],
            "name": "Journal of Mormon History 44",
            "volumeNumber": "44"
        }
    }
}
</script>