From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

How to Edit Individual Cells in Excel from LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

This VI shows how to edit individual cells in a pre-existing Excel spreadsheet. 

Description

We are using ActiveX controls with property and invoke nodes to programatically change values and styles in Excel going either cell by cell or by changing a range of values. 

Building the Example below:

1) Open Excel programatically with an ActiveX Property Node that is linked into a "Workbooks" ActiveX Invoke Node

(For this example, we send the path file from a control on the front panel)

2) Open the specific sheet within the Excel file using the name of the sheet
3) Make a Worksheet Invoke Node and use the refnum constant from that Invoke Node to select your sheet
4) Find a range in that sheet to edit by using the Range property in the Worksheet Invoke Node
5) Use the range refnum to edit the full range you selected or send in coordinates and the new values all over the worksheet
6) Close all open references

Hardware and Software Requirements

This needs the ActiveX framework that comes with all Windows Operating systems. LabVIEW 2012 or compatible. 

Steps to Implement or Execute Code

1) Download the attached VI

2) Type out the path and Sheet Name of the excel sheet you want to edit

3) Run the VI

Block Diagram.png

Additional Information or References

For more information, please see the example VI below. 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.