Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

ETABS API using Excel VBA

Status
Not open for further replies.

Kevz

Structural
Jul 16, 2024
1
Hello! I just started using ETABS API and I'm having a trouble on exporting table to excel. Can someone correct my code below? Thanks

Sub ExportFramePropertyModifiersToExcel()

'set the following flag to True to attach to an existing instance of the program
'otherwise a new instance of the program will be started
Dim AttachToInstance As Boolean
AttachToInstance = True

'create API helper object
Dim myHelper As ETABSv1.cHelper
Set myHelper = New ETABSv1.Helper

'dimension the ETABS Object as cOAPI type
Dim myETABSObject As ETABSv1.cOAPI
Set myETABSObject = myHelper.GetObject("CSI.ETABS.API.ETABSObject")

'use ret to check return values of API calls
Dim ret As Long

'get a reference to cSapModel to access all API classes and functions
Dim mySapModel As ETABSv1.cSapModel
Set mySapModel = myETABSObject.SapModel

' Access the cDatabaseTables interface
Set DatabaseTables = mySapModel.DatabaseTables

Dim TableKeyList() As String
Dim WindowHandle As Integer

TableKeyList() = Range("A3:A4").Value

ret = DatabaseTables.ShowTablesInExcel(TableKeyList, 1)

End Sub
 
Replies continue below

Recommended for you

Might help to know where the code fails and what the vba error message says.

I don't know the ETABS api, but a few things I noticed:
-myHelper dim type is different to the set object. It could be fine, but its not how Microsoft does their api.

-mySapModel similar as myHelper.

-If you have option explicit set, you didn't dim DatabaseTables.

-Unless ShowTablesInExcel does it, you never output to the spreadsheet. I'm not sure how it would since TableKeyList is not a range object but just an array.

-I assume that the ETABS reference as been activated for your spreadsheet so that VBA knows what these objects are.
 
I don't know the Etabs API (or even Etabs) either, but the lines:

Dim TableKeyList() As String
Dim WindowHandle As Integer
TableKeyList() = Range("A3:A4").Value

Don't look right.

You can import data from a range into a variant array if you declare it as a Variant.

The code below works for me:

Sub CheckString()
Dim TableKeyList As Variant

TableKeyList = Range("A3:A4").Value
Range("C3:C4").Value = TableKeyList
End Sub

If the API requires TableKeyList to be an Excel Range object, you will need something like:

Sub CheckString2()
Dim TableKeyList As Range

Set TableKeyList = Range("A6:A7")
Range("C6:C7").Value = TableKeyList.Value
End Sub

Doug Jenkins
Interactive Design Services
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor