VBA is closely related to Visual Basic and uses the Visual Basic Runtime, but can normally only run code within [most Microsoft Office applications].1 VBA can indirectly use most of the code provided with the NI-DAQmx Examples for Visual Basic 6.0. This example uses parts of the Read Dig Chan example source code to quickly implement a VBA program utilizing DAQmx within Microsoft Excel. Please see the attached Microsoft Excel spreadsheet to follow along with the setup instructions below.
1.0 First Open Microsoft Excel, click the Office Button and open the Excel Options window.
2.0 Navigate to Excel Options»Popular»Top options for working with Excel»Show Developers tab in the Ribbon»Ok
This will add the Developer tab where you can access the Visual Basic Editor.
2.1 You can also add a Visual Basic Editor command button at the top of the window by navigating to Excel Options»Customize»Choose commands from»Developer Tab»Visual Basic»Add»Ok
A Visual Basic button appears in the title bar
Now you will need to add in the DAQmx C reference type library. This is installed with NI-DAQmx driver into the Windows system folder.
4.0 From the Visual Basic Editor, click Tools»References
5.0 In the References window check the NI DAQmx C API type library. If it is not listed, browse to C:\windows\system32\nidaqmx.tlb
6.0 Start the example by opening UserForm1 and navigating to Run»Run Sub/User Form
Please also note that the DAQmxErrChk function is included in a separate module in the VBAProject. This function is needed to retrieve the error code of any DAQmx call that fails or returns a warning. The source code for the error checking module can be found in the NI-DAQmx Examples for Visual Basic 6.0 knowledge base article