11-30-2015 02:37 AM
Hi Community,
I'd like to execute Visual Basic commands on an Excel sheet without having the commands actually in the Excel file. Is there way to do that from LabVIEW.
Please note that I know how to execute a macro in an Excel file from LabVIEW. My question is if I can put the VBA script into LabVIEW and execute it on the excel file.
thanks!
11-30-2015 02:51 AM
You cannot execute the VBA script directly IN LV. Maybe there is an option to call it OUTSIDE, similar to use Excel API to execute the script.
However, the biggest question is: What is the script doing? Why do you want to have it outside of Excel?
I expect all the script commands to be available via the Excel API as well. That means: You can write LV code which does what your Macro does.
I don't know if that is what you are looking for though.....
Norbert
11-30-2015 02:59 AM
I am pretty sure that a macro can be put into an text file and can be called, but for different reasons I'd like to have it in the LV code if possible. Yeah, I am pretty sure that everything can be done with API calls from LabVIEW although its significantly more difficult than from VBA.
I am wondering if I can create a macro from LabVIEW with API calls, then execute it and then delete it...
11-30-2015 03:31 AM
@1984 wrote:
I am pretty sure that a macro can be put into an text file and can be called, but for different reasons I'd like to have it in the LV code if possible. Yeah, I am pretty sure that everything can be done with API calls from LabVIEW although its significantly more difficult than from VBA.
I am wondering if I can create a macro from LabVIEW with API calls, then execute it and then delete it...
If you can call a text file containing a macro it should be easy to write a file, call it and delete it.
/Y
11-30-2015 03:33 AM
@1984 wrote:
[...]
I am wondering if I can create a macro from LabVIEW with API calls, then execute it and then delete it...
Essentially, you are talking about a script interpreter. You can write such a thing in LV, but i'm not sure if it's worth the effort.
What is the use-case for this?
Norbert
11-30-2015 03:37 AM
What I meant is not to create a script interpreter, but creating a macro with an API call, filling it with the VBA content, calling the macro and then deleting the macro.
11-30-2015 03:39 AM
True... its just not very elegant.
11-30-2015 03:48 AM
I recommend you to use MSDN or Google for further investigations.
I did that for a couple of minutes just to find out that there is no easy solution. For what i've seen you have two options for "external macros" in Excel:
a) Store the macri in a different Excel sheet (xlsx) and call that "on top" of your data workbook. This can, as far as i understood, be done when loading the data workbook.
b) Create an Excel Add-In (xla) and install it.
However, both approaches don't seem promising for flexibility of "dynamic script creation"....
Norbert