Example Code

Run and Excel Macro using Report Generation Toolkit in LabVIEW 8.6

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 simple example shows how to use Report Generation Toolkit to process Excel document.


Description


This code open an Excel document Book1 and use the Excel Import Module VI with the Excel Run Macro VI to run macros defined in external modules to process the Excel document. After the macro runs, use the Excel Remove Module VI to remove the external module from the Visual Basic project. Finally, save the results as a new Excel document named Book2. 


Requirements

  • LabVIEW 2012 (or compatible)
  • Report Generation Toolkit
  • Microsoft Office 


Steps to Implement or Execute Code

  1. Ensure Report Generation Toolkit and Microsoft Office has been installed
  2. Open an Excel document and rename as Book1
  3. Run the program
  4. Compare the newly generated Excel document named Book2 with Book1 and observe the results 

Additional Information or References

Why do I get error -41113 at Excel Import Module VI when using the Report Generation Toolkit?

Solution:

To get rid of this error you must follow the advice from the error message and make Visual Basic a trusted macro source.

 

In Microsoft Excel 2003 go to Tools»Options»Security»Macro Security»Trusted Publishers and click the checkbox next to both Trust all installed add-ins and templates and Trust access to Visual Basic Project.

 

In Microsoft Excel 2007, click the Office Button in the top left then click Excel Options. Click on Trust Center from the list on the left, and then click Trust Center Settings... Click on Macro Settings and check the box for Trust access to the VBA project object model.

 

In Microsoft Excel 2010 and later, click the File Tab in the top left then click Options. Click on Trust Center from the list on the left, and then click Trust Center Settings... Click on Macro Settings and check the box for Trust access to the VBA project object model.

 

It may be necessary to restart the computer after making this change for it to take effect in LabVIEW.

Related Links:

 Report Generation Toolkit Compatibility with Microsoft Office and LabVIEW

 

VI Block Diagram

 5-304.png

 **This document has been updated to meet the current required format for the NI Code Exchange.**

National Instruments

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

Comments
missman
Member
Member
on

缺一大堆子Vi,拜托将整个项目上传可以吗?