COM Interface in VBA | 1. Opening RFEM, Creating and Saving Model, Closing RFEM

Tips & Tricks

The first part of the post about the COM interface describes opening and closing RFEM. The programming language VBA is used in Excel, however the program sequence is the same as for programming with C#. First, it is necessary to add the corresponding reference in VBA to recognize the commands for the interface. The figure on the left shows the example of RFEM 5.

Then, the source code for a simple program. You can create the interface for the model first and then open the program using the model. After saving, the program is closed.

It is always good to use the error handler in order to detect and display the possible input/output problems. If there is a problem, the license is unlocked again so you can access RFEM/RSTAB. Further explanation can be found in the source code.

Sub CreateModel()

' Firstly, an interface
' to a new model is created.
Dim iModel As RFEM5.model
Set iModel = New RFEM5.model

' Here, the model name is defined,
' either the content of cell B2 of sheet Table1
' or, if empty, "test.rf5".
Dim modelName As String

If IsEmpty(Worksheets("Table1").Range("B2").Value) Then
modelName = "test01.rf5"
modelName = CStr(Worksheets("Tabelle1").Range("B2").Value)
End If

' Transfer of the model name to the interface.

' It is possible to specify a model description here.

' Error handling routine.
On Error GoTo e

Dim iApp As RFEM5.Application
' Interface to the program is opened.
' (Program is started.)
Set iApp = iModel.GetApplication

' COM license and program access are blocked.

' Program is displayed in the foreground.

' Model is saved at "C:\temp" .
iModel.Save("C:\temp\" & modelName)

e: If Err.Number <> 0 Then MsgBox Err.Description, , Err.Source

' COM license is unblocked, program access possible again.
' Program is closed.

End Sub


Contact us

Do you have questions or need advice?
Contact our free e-mail, chat, or forum support or find various suggested solutions and useful tips on our FAQ page.

(267) 702-2815

RFEM Main Program
RFEM 5.xx

Main Program

Structural engineering software for finite element analysis (FEA) of planar and spatial structural systems consisting of plates, walls, shells, members (beams), solids and contact elements

Price of First License
3,540.00 USD
RFEM Other
RF-COM 5.xx

Add-on Module

Programmable interface (API) based on the COM technology

Price of First License
580.00 USD