首页 > 解决方案 > 错误 91,VBA Excel,CATIA API:未设置变量

问题描述

我正在尝试访问 CATIA 函数以在 Excel 宏中更新 Smarteam 中的文档生命周期,以下几行

Dim CATEngine As StiEngine

Set CATEngine = CATIA.GetItem("CAIEngine")

不断返回error 91: variable not set问题。

从这个链接我不是为什么像这样的简单命令会返回这个错误 http://catiadoc.free.fr/online/interfaces/interface_StiEngine.htm

也许我没有正确加载某些库/集成?欢迎所有见解

这是来自其他模块的代码,非选项显式和非全局定义(我尝试了全局定义 CATIAEngine,但它返回歧义错误):

Sub checkUUID()

    Dim FoundObj As ISmObject
    Dim wbNew As Workbook, wsNew As Worksheet
    Dim checkDOCUUID As Document
    Dim Products As Products
    Set wbNew = ActiveWorkbook
    Set wsNew = wbNew.Sheets(1)
    Set SmEngine = CreateObject("SmApplic.SmFreeThreadedEngine")
    SmEngine.Init "SmTeam32"
    Set SmSession = CreateObject("SmApplic.SmSession")
    SmSession.Init SmEngine, "MySession", "SmTeam32"
    wsNew.Activate
    Dim childList() As String

    Set SmDatabase = SmEngine.Databases(0)
    ID = SmDatabase.Alias           'Provider=SQLOLEDB.1;Persis Security Info=False;User ID=SMARTUSER;Initial Catalog=Smarteam;Data Source=ST2008SQL\SQLSMARTEAM
    Pass = SmDatabase.Password      'ProvidSMARTEAM_7kikX/GtJNG6d7BcYeTi8cf4IuVCgWjDrvo/Oo4xdZgHjg+fDpzdEEll7tcGT96tcB7pP8krz1hw6pDgzXchTrwfm1t0FKGsDK6C7EvQW7+grVLwZamcVpnmz6ibMWAogHWcLM+H6ID87NIXwBLXNaJxm3tKg6eZ84nzNSkCGFc=
    Call SmSession.OpenDatabaseConnection(ID, Pass, True)

    If SmSession.IsServiceEnabled("SmGUISrv.SmCommonGUI", Reason) Then
        Set GUIServices = SmSession.GetService("SmGUISrv.SmCommonGUI")
    End If

    GUIServices.Dialogs.ExecuteLogin

    Set FSO = CreateObject("Scripting.filesystemobject")


    tempFolderName = "C:\ST Temp\UUID\"
    If Len(Dir("C:\ST Temp\", vbDirectory)) = 0 Then
        MkDir "C:\ST Temp\"
    End If

    If Len(Dir("C:\ST Temp\UUID\", vbDirectory)) = 0 Then
        MkDir tempFolderName
    End If

    CatiaConnect                                'launch Catia V5
    CatIntgConnect                              'connect to ST using ST CATIA integration
    CATIA.DisplayFileAlerts = False             'disable all the warning's and disables all the user interaction





CatIntgConnect

Sub CatIntgConnect()

    Set CATEngine = CATIA.GetItem("CAIEngine")

    ' -----------------------------------------------------------
    ' CATIA V5 Operations are performed in the background
    ' -----------------------------------------------------------
    Dim BooleanUI As Boolean
    If (CATEngine.UseGraphicalUI) = True Then
            CATEngine.UseGraphicalUI = True
            BooleanUI = True
    End If
    ' -----------------------------------------------------------
    ' Connect to the SmarTeam database (if not already connected)
    ' -----------------------------------------------------------
    Dim BoolConnect As Boolean
    BoolConnect = False
    If Not CATEngine.IsConnected() = True Then
             CATEngine.Connect "", ""             'to perform automation via CATIA SMARTEAM integration, must type in the userid and password
             BoolConnect = True
    End If
End Sub

标签: excelvbaapicatia

解决方案


推荐阅读