×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Can't start new instance of SAP2000v18 from VBA

Can't start new instance of SAP2000v18 from VBA

Can't start new instance of SAP2000v18 from VBA

(OP)
I have the following VBA code in a Module within Excel:

Sub Prueba_1(AttachToInstance)
'AttachToInstance = True: usa una instancia de SAP ya abierta (no abre un nuevo SAP)
'AttachToInstance = False: abre una nueva instancia de SAP

Dim ret As Long

'Path del ejecutable del SAP
Dim ProgramPath As String
ProgramPath = "C:\Program Files\Computers and Structures\SAP2000 18.1.1\SAP2000.exe"

'Path del fichero SDB
Dim ModelPath As String
ModelPath = Hoja1.txt_Fichero.Text

'Crear instancia SAP
Dim mySapObject As cOAPI
Set mySapObject = Nothing

If AttachToInstance = True Then
'Abrir modelo en una instancia de SAP ya abierta
'Obtener el objeto de SAP activo
Set mySapObject = GetObject(, "CSI.SAP2000.API.SapObject")
Else
'Crear una nueva instancia de SAP
'Crear objeto OAPI helper
Dim myHelper As cHelper
Set myHelper = New Helper
'Obtener el objeto SAP
Set mySapObject = myHelper.CreateObject(ProgramPath)
'Iniciar aplicación
mySapObject.ApplicationStart
End If

'Obtener una referencia a cSapModel para acceder a todas las clases y funciones de OAPI
Dim mySapModel As cSapModel
Set mySapModel = mySapObject.SapModel

'Inicializar modelo
ret = mySapModel.InitializeNewModel

'Abrir modelo de SAP definido en el cuadro de texto
ret = mySapModel.File.OpenFile(ModelPath)

....

End Sub

If I try to work in an already open instance of SAP (with AttachToInstance=True) it works like a charm.
However if I try to open a new instance (AttachToInstance=False) I get an error "ActiveX component can't create object" when running "Set myHelper = New Helper".

I can't see where the problem is, as long as the "CSI_OAPI_Documentation_v18.hlp" says it has to be done that way, including some examples.

Of course I have included the reference to SAP2000v18.TLB in Excel, in case anybody has this doubt.

Any help would be really appreciated.

Thanks.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources