LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Fully interact with an Excel macro through LabVIEW

The "Path" control is not a path control. It is a VBA (Visual Basic for Applications) string control which i use in the excel macro to set the path of the file that will be created by pushing the "Write" button.

 

Attached a new archive containing the VI compiled for LabVIEW 8.6.

0 Kudos
Message 11 of 23
(3,252 Views)

@aRCo wrote:

The "Path" control is not a path control. It is a VBA (Visual Basic for Applications) string control which i use in the excel macro to set the path of the file that will be created by pushing the "Write" button.

 

Attached a new archive containing the VI compiled for LabVIEW 8.6.


Again, why you writing a macro to do work that LabVIEW can do????

 

Why not just run the macro in Excel?

 

LabVIEW code in conjunction with ActiveX replaces the macro. Do you not understand that?

0 Kudos
Message 12 of 23
(3,247 Views)

Briefly...

 

A third person (not me) developed a complex Excel macro which serves to download a firmware (a .bin file) to a device. The macro comes with:

1 - a string control used to set the path of the firmware to download

2 - a string indicator used to get the status of the device

3 - a button to start the download

4 - a popup message which automatically raises at the end of the download showing the result

 

I neither want to take a look at the code of the macro nor use the macro manually. The only thing i would like to do is to open Excel and interact automatically (programmatically) with the macro through LabVIEW.

 

Now, in order to avoid sharing things that are not mine, i decided to realize an Excel macro example (the "SimpleMacro.xls" file).

 

Hope everything is clear now, mates!

 

 

Message 13 of 23
(3,239 Views)

It is too bad you don't want to understand the macro because it often is easier to write LabVIEW to duplicate it then to automate it via ActiveX.

 

To point you in the general direction, the embedded controls on your worksheets are OLEObjects. http://msdn.microsoft.com/en-us/library/bb179198%28v=office.12%29

Enjoy!

 

 

0 Kudos
Message 14 of 23
(3,229 Views)

aRCo wrote:

I neither want to take a look at the code of the macro nor use the macro manually. The only thing i would like to do is to open Excel and interact automatically (programmatically) with the macro through LabVIEW.


You can't "interact" with a macro. All you can do is Run it. If the macro has input parameters, then the Run method allows you to specify them. If the macro is written in such a way that it gets values from specific cells or objects on the spreadsheet, then you need to set the cell values prior to calling the macro. If you're talking about objects such as textboxes, then you need to set these. You will need to look at the Excel object model on how to set textboxes (if that's even possible).

0 Kudos
Message 15 of 23
(3,222 Views)

Apparently the macro depends on the contents of textboxes which LabVIEW can read and write. These textboxes are OLEObjects in the Excel Object Model.

 

To run a macro, use Application.Run method.

 

 

 

 

 

 

0 Kudos
Message 16 of 23
(3,216 Views)

Thanks for the replies.

I succeeded opening/closing both the Excel environment and the workbook (the "SimpleMacro.xls" file).

Now i would like to get/set the value of an object (the "Path" string, both in the "WriteToFile" and in the "ReadFromFile" sheet).

Clues on which is the correct sequence of methods/properties to call in the "RunExcelMacro" VI?

 

0 Kudos
Message 17 of 23
(3,206 Views)

It would be the same sequence as if you were writing a separate macro to call your macro. For that your best bet is go to Excel forums and look for the answer, since you're asking an Excel-specific question, not a LabVIEW one.

0 Kudos
Message 18 of 23
(3,194 Views)

@smercurio_fc wrote:

It would be the same sequence as if you were writing a separate macro to call your macro. For that your best bet is go to Excel forums and look for the answer, since you're asking an Excel-specific question, not a LabVIEW one.



You are not understanding his question.

 

Basically he has only gotten as far as being able to start Excel and close Excel and open and close his workbook.

Nevermind that this is already in the LabVIEW examples.

 

He wants to know now how to do everything else which apparently is to have LabVIEW read/write to his textboxes and everything else related to running his improvised macro.

 

 

 

 

0 Kudos
Message 19 of 23
(3,189 Views)

In order to clarify ideas, i uploaded an image showing the code i used to get few information such as "# of sheets", "Book name", "Selected sheet name", "# of objects". This piece of code works fine.

 

Now i need to access the value of the OLE objects in order to get or set it. Objects are: "WritePath" and "WrittenText" in the WriteToFile sheet and "ReadPath" and ReadText" in the ReadFromFile sheet.

 

Smiley Tongue

0 Kudos
Message 20 of 23
(3,181 Views)