|How to use ActiveX in Excel|
The following is a step-by-step lesson on how to use ActiveX in Excel. If you wish to log data to Excel spreadsheet directly, check this out
32-bit ActiveX doesn't work in the VBA environment of 64-bit version Excel, that's why our WinDaq add-on Excel Link stay outside of Excel and provide data link between WinDaq and any version of Excel.
In this lesson, we will use Ultimaserial ActiveX to develop a data acquisition application with DATAQ's Starter kit.
This sample will acquire data once per second from channel 1 of DI-158 and fill up the first twenty rows of the first column of the spreadsheet continuously. Once you understand this simple program, you can take a closer look at more Excel samples.
Note: In this example, instead of embedding all the controls and codes in the spreadsheet directly, I use a form to collect all these so that it acts similar to the other Excel samples.
Before we start, please download and install UltimaSerial then run Microsoft Excel.
1) Follow Tool->Macro->Visual BASIC Editor, and you should enter Microsoft Visual Basic Editor:
2) In the VB Editor, follow Insert->UserForm, and you should see this:
3) Move the mouse cursor to ToolBox. Click the right-button on the mouse and follow Additional Controls ...
4) In the Additional Controls dialogue box, select UltimaSerial Control and Timer Object , and hit OK to bring the two controls into the ToolBox. If you don't see these two controls in the list, you need to install UltimaSerial. Now your ToolBox should be like this:
5) Place two command buttons along with UltimaSerial and Timer in the UserForm. Now your screen should be like this:
6) Double-click on the CommandButton1, CommandButton2, Ultimaserial, and Timer Objects on the UserForm to create the codes for them.
7) In the Visual Basic code editor, change the default codes (If you decide to type in the codes, you will notice the properties and methods will be displayed in a drop-down menu once you typed in ultimaserial1.)
To (Watch for the blue text, we assume button Command1 and 2 for Start and Stop action)
9) Close the Excel Visual Basic Editor, and back to Excel. Make sure you can see the Control ToolBox in your toolbar (the third row in my sample below) If you don't see it, follow View->Toolbars->Control ToolBox to enable it.
10) Add a button from the Control ToolBox to the spreadsheet (Notice the first button on the Control ToolBox toolbar is down. This indicates we are still in Design Mode)
11) Double-click on the button to enter Visual Basic Editor for sheet1. Now change the default code
To: (Watch for the blue text)
12) Back to Excel. Exit Design Mode (The Design Mode button is the first one in the Control ToolBox toolbar, when it is down, it is Design Mode; when it is up, it is Run Mode. See Step 10) for more detail )
Now you can click on the button on the spreadsheet to bring up UserForm1. Click on the CommandButton1 on UserForm1 and you will see data begin to fill the first column of the spreadsheet. Click on CommandButton2 to stop the acquisition.
Please check this out to find out how to pace the data acquisition rate more accurately.
Here you can learn how to send data to Excel directly from a VB program.
Last update: 11/18/16
Copyright: 2000-2005 www.UltimaSerial.com