Using the SAP2000 v18 API in VBA
Using the SAP2000 v18 API in VBA
(OP)
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 --> VBA
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 




RE: Using the SAP2000 v18 API in VBA
After reporting to CSI, they answered that many customers have the same problem when running simultaneously 64 bits version of SAP and 32 bits version of Office, and suggested installing 32 bits version of SAP.
I don't know if that is your case.
Unfortunately we haven't found the moment to make any further tests, but I hope at least to have put some light on your question.
We would really appreciate your report in case you find a solution.
RE: Using the SAP2000 v18 API in VBA
Using VB.Net in Visual studio Community worked fine and was a lot easier than programming in vba/excel. The only problem I've been having so far is the Results.JointRespSpec() function that gives me the wrong results but I didn't need it for my project.