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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Running Excel macro to format sheet from Labview?

Hey, thanks in advance.

I am trying to put together a VI that can run a macro in Excel. The macro I recorded simply formats some of the cells to be bold, sets the widths/heigths, merges some cells, adds some border, etc. I have been trying to piece together a bunch of examples from the discussion forum, from LV, etc. for doing this with ActiveX. I'm really starting to bang my head on the desk... all I need to do is make all the data my program sends to Excel pretty without having the operator (or supervisor) have to do this manually.

Does anyone have an example of a program that opens a file based on an extension you give it, runs a macro, then closes the file? Or other suggestions for doing this?

All the other examples I've looked at are different enough that I just can't make it work.

Thanks a million!
0 Kudos
Message 1 of 3
(2,438 Views)
Well adam welcome to the world of active x. One trick I have learned with using it is when I want to do something in the program that uses macros (ie word, excel.) then what I do is create the macro and look at the code, then I will usually duplicate the code in labview using invoke and property nodes just because I do it that way does not mean it is the best way. I do it this way so I do not have to worry about someone deleting the macro. But running the macro is not trivial if you decide to go that route. Here are a bunch of vi's that will help you out.

Message Edited by jhoskins on 04-27-2005 09:00 AM

Message Edited by jhoskins on 04-27-2005 09:00 AM




Joe.
"NOTHING IS EVER EASY"
0 Kudos
Message 2 of 3
(2,428 Views)
In the built-in LabVIEW examples is one called Write Table to XL. It will open a workbook, select a sheet, write a table, then save and close the workbook.

If you chop out the part that writes the table, you can replace it with the macro. The only function you need is the method node Application.Run. The first parameter is the name of the macro to run. All of the Argument parameters are optional.

If you do not have the Application reference convenient in your application, you can use the property node Worksheet.Application to get it.
Michael Munroe, CLD, CTD, MCP
Automate 1M+ VI Search, Sort and Edit operations with Property Inspector 5.0, now with a new Interactive Window Manager!
Now supports full project automation using one-click custom macros or CLI.
0 Kudos
Message 3 of 3
(2,397 Views)