VBA

<< Click to Display Table of Contents >>

Navigation:  Flexcom > Theory > Postprocessing > Custom Postprocessing > Excel Add-in >

VBA

Previous pageNext page

Overview

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.

Excel Developer Tab

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.

ExcelDeveloperTab

Enable the Developer tab in the Customize Ribbon options

Adding a Reference

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.

VBbutton

Visual Basic button

3.On the Tools menu of the IDE, click References, then select Flexcom Database Access Library and click OK.

VBA_References

Adding a reference to the Flexcom Database Access Library in the VBA IDE

Adding VBA Code

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.

AddVBModule

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.

DefineDB.Syntax

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.

UseDB.Syntax

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.

AddMacroButton

Creating a button in an Excel workbook

Examples

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.