You can use LabVIEW, LabWindows/CVI (now a component of Measurement Studio), and other NI software to communicate with Microsoft Excel via ActiveX Automation. ActiveX is a technology that allows you to reuse code (written in any language) that has a defined interface. Then, you can make that code accessible to other applications. ActiveX Automation applications interact in a Client/Server model, where the Automation Server exposes objects that can be controlled by the Automation Client (also known as the Automation Controller).
"Automation Object" is a modern term for a programming interface. Automation Objects can have methods -- which are functions that perform an action on the object, such as saving or printing it. In addition, the Automation Objects can have properties -- which are variables that set or return information about the state of an object, such as its width, height, or state.
When you write a LabVIEW or LabWindows/CVI application to control Excel, your program acts as the Automation client and Excel acts as the Automation server. Excel exposes numerous objects, including workbooks, worksheets, charts, and ranges of cells that can be accessed through automation. From LabVIEW or LabWindows/CVI, you can only manipulate the objects that Excel exposes to other applications. This means that Excel determines what it exposes, and what values and variables must be passed to each method or property.
For more information on how LabVIEW supports ActiveX, see the related link ActiveX and LabVIEW.
2. Basics of using LabVIEW with Excel
To integrate Excel objects with your LabVIEW VIs, you need to understand the Excel object model as well as how to perform ActiveX automation from LabVIEW. For information about the Excel Object Model, see the Excel Object Model Help file located on your Microsoft Office CD. In addition, the Microsoft Object Model Guide lists the organization of all the objects in the Office 97 applications.
The basic procedure is to open a reference to Excel from LabVIEW, invoke methods and get/set properties, and then close the reference. Notice that since Excel will allow you to open references to different objects in its hierarchy, you must close each one individually. In LabVIEW 7.1 or earlier, refer to the ActiveX Support chapter of the LabVIEW User Manual (linked below) for more information about using LabVIEW with Excel. In LabVIEW 8.0 or later, refer to the Using ActiveX with LabVIEW topic in the LabVIEW Help (linked below).
For basic LabVIEW examples of printing with Excel, reading and writing data to Excel, running an Excel macro, and using the SaveAs method, see the related link below Using LabVIEW as an Automation Client with Microsoft Excel. As of LabVIEW 2010, you can easily export data and images to Excel. To learn more about this functionality, see the LabVIEW Help.
Plus, for a specific example of how to use the ActiveX Automation VIs to access cell values from Excel 97/2000 worksheets, see the related link Reading Values from Microsoft Excel 97 or Excel 2000 Worksheets. For a specific example of a LabVIEW program that accepts the path and file name of an Excel spreadsheet file and uses background printing, see the related link Printing Excel Spreadsheet Files Using ActiveX.
Using LabVIEW as an Automation Client with Microsoft Excel
Printing Excel Spreadsheet Files Using ActiveX
LabVIEW User Manual
LabVIEW Help: Using ActiveX with LabVIEW
3. Basics of using LabWindows/CVI with Excel
LabWindows/CVI provides a wizard to guide you through development of applications that invoke Excel. Go to Tools>>Create ActiveX Automation Controller and browse the Server's exposed objects to create a CVI instrument driver (a set of C functions) that wrap the methods or properties of the object. By calling the functions in the generated instrument driver from within a CVI program, you can invoke the methods and set or get the properties of the Server objects.
The CVI IDE (Integrated Development Environment) application is also an Automation Server. This means that you can control the CVI IDE from within other Automation Controllers. For example, you can move files in and out of CVI projects, compile a file, or build a project from within another application.
For examples of how to use LabWindows/CVI to control Excel 97 and Excel 2000 through the ActiveX Automation interfaces, see the related links below Controlling Microsoft Excel for Office 2000 with an ActiveX Automation Server and Controlling Microsoft Excel for Office 97 through Active X Automation.
Plus, for examples for how to use Active X events from Excel 97 or Excel 2000, see the related links Handling ActiveX Automation Events in Excel for Office 2000 and Handling Active X Automation Events in Excel for Office 97.
Controlling Microsoft Excel for Office 2000 with an ActiveX Automation Server
Controlling Microsoft Excel for Office 97 through ActiveX Automation
Handling ActiveX Automation Events in Excel for Office 2000
Handling ActiveX Automation Events in Excel for Office 97
4. Using Excel with Measure and HiQ
Finally, you can use Excel with the Measure and HiQ products -- as shown in the related link below VBA with Measure and HiQ. The example shows you how to create dialog boxes in Excel, invoke Measure tasks from Visual Basic for Applications (VBA), and control HiQ from Visual Basic with its automation server. It also shows you an easy way to save and restore settings using the registry commands in Visual Basic.