The Flexcom Excel add-in may also be used with VBA and the same functions are available as in an Excel worksheet. The following steps will help you to set up your VBA application to access a Flexcom database in Microsoft Excel 2010. The procedure should be similar for other versions of Excel.
1.The first step is to enable the Developer tab in Excel.
2.In Excel, click the File tab. On the Microsoft Office Backstage view that appears, click the Options button and then click the Customize Ribbon tab.
3.On the Main Tabs list on the right, select the Developer option.
Enable the Developer tab in the Customize Ribbon options
1.Next you to add a reference to the Flexcom Database Access Library to the project.
2.Go to the Developer Tab and click on the Visual Basic button on the left of the ribbon. This will open the VBA Integrated Development Environment (IDE) in a new window.
Visual Basic button
3.On the Tools menu of the IDE, click References, then select Flexcom Database Access Library and click OK.
Adding a reference to the Flexcom Database Access Library in the VBA IDE
1.Next, create a new module by right clicking on the VBA project icon, then click on Insert and select the Module option, as shown in the figure below.
Open a module in the Visual Basic project
2.To create an instance of the DatabaseAccess class, define a new parameter, named “DB” in this example, as illustrated in the below figure.
Create a new instance of the DatabaseAccess class
3.To access all the Flexcom Database Access functions use the “DB.” syntax. The figure below shows that once the dot is typed, VBA helps you by displaying a list of member functions to pick from.
VBA environment suggests the functions available
Once you are finished adding code to a macro, it may be ran by pressing the Run button or pressing the F5 key within the VBA environment. Alternatively, it is possible to create a button in the active Excel workbook and assigning the macro to it. To do this, click Insert Controls on the Developer tab and select Button (Form Control), highlighted in the figure below. On the dialog box that appears, choose the macro you want the button to run and click OK.
Creating a button in an Excel workbook
The Node Positions Example article gives an example of a simple VBA macro to extract node positions from the database and write them to files. The Statistics Example article gives an example of a more complex VBA macro to calculate statistics such as mean and standard deviation of effective tension.