etienne201
Structural
- Jul 20, 2016
- 4
As anyone here successfully used the API in VBA?
Even after adding the reference to SAP2000v18.TLB, the example from the documentation doesn't work.
I get an error 429 "ActiveX component can't create object" at line 8 ("set SapObject = Create...)
Is there anything else that typicality need to be change before using the API ?
Code:
Sub RunSapAnalysisModel()
'dimension variables
Dim SapObject As cOAPI
Dim SapModel As cSapModel
Dim ret As Long
'create Sap2000 object
Set SapObject = CreateObject("CSI.SAP2000.API.SapObject")
'start Sap2000 application
SapObject.ApplicationStart
'create SapModel object
Set SapModel = SapObject.SapModel
'initialize model
ret = SapModel.InitializeNewModel
'create model from template
ret = SapModel.File.New2DFrame(PortalFrame, 3, 124, 3, 200)
'save model
ret = SapModel.File.Save("C:\SapAPI\x.sdb")
'run model (this will create the analysis model)
ret = SapModel.Analyze.RunAnalysis
'close Sap2000
SapObject.ApplicationExit False
Set SapModel = Nothing
Set SapObject = Nothing
End Sub