Import M-N-V from Robot to Excel by VBA code

You may have develop your Excel VBA code to check the capacity of a column section. It is sometime very hard to copy all the M-N-V results of a column for many load combinations to your code. In this example, we will see how to copy an output from Autodesk Robot to Excel using VBA code.

Create a model in Robot

In this example, Autodesk Robot 2017 is used. Ensure that Autodesk Robot SDK is already installed.

Create a model in robot, run the model, keep the model open with results while compiling the code in your Excel VBA.

Suppose you want to read M-N-V for the column number 2 and for the load combination 4:ULS-1.

Create Excel file to receive the M-N-V from Robot

Create a new Excel file and save it with “Save as type = excel macro-enabled workbook (*.xlsm)”

Arrange the Excel sheet as this example:


Open VBA editor >> Tools>> References… >> Tick “Robot Object Model ver. 16.0” for Autodesk Structural Analysis 2017. Click OK to close References dialogbox.

Create a module and try the following code:

Sub read_data_from_robot()


Dim robapp As New RobotApplication
Dim serv As RobotBarForceServer
Set serv = robapp.Project.Structure.Results.Bars.Forces

BAR_ID = Range("C2") 'ID number of column
CASE_ID = Range("C3") 'Load combination to read from

Range("D6") = serv.Value(BAR_ID, CASE_ID, 0#).MY 'for My at end i
Range("D7") = serv.Value(BAR_ID, CASE_ID, 1#).MY 'for My at end j
Range("E6") = serv.Value(BAR_ID, CASE_ID, 0#).MZ
Range("E7") = serv.Value(BAR_ID, CASE_ID, 1#).MZ
Range("C6") = serv.Value(BAR_ID, CASE_ID, 0#).FX 'Pu for end i
Range("C7") = serv.Value(BAR_ID, CASE_ID, 1#).FX
End Sub

Run the code, I get the following results. The unit are [N] and [m].

Speak Your Mind

*