ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Automating Macros for CSV files (https://www.excelbanter.com/excel-programming/373416-automating-macros-csv-files.html)

griffin_5338

Automating Macros for CSV files
 
Been all over the 'net looking for an answer to this one, here goes....

I need to collect data in a C++ Net application, then from that same
application automatically (with no keys pressed) do the following:

1) Save the file as an Excel-compatible dataset (I chose CSV for its
simplicity)

2) Fire up Excel and load up the dataset into a worksheet

3) Execute a very extensive macro (over 800 lines) in Excel - this macro can
be installed as a global macro e.g. XLstart directory (see note below) as a
separate file or worksheet
(optional)

4) Leave the focus on the Excel window so the results will appear foremost
to the user


Seems simple, and I've had success with steps 1 and 2 using the
Microsoft::Office::Interop method. HOWEVER, when Excel is started from my
C++ application, none of the global macros are available. This seems to be
some kind of security limitation of global macros. Yes, I tried all four
security settings to no avail. (If you fire up Excel by itself, global
macros in XLStart are available -- but not when C++/Interop starts Excel.
Same thing when starting Excel from a VBScript.)

Is there a way to get Interop/Excel to pull in or execute a macro from a
separate worksheet?

Is it possible to get around the security limitation so global macros are
available via Interop-invoked Excel?

Is there something aside from Interop that I should use to fire up Excel and
get this macro running? One thought was to import an existing Excel document
with the macro already in it and then run the macro, but I can't find a way
to import into a worksheet.


If it helps, my configuration is: C++ Net Standard Edition, Excel 2000
Professional, all on Windows XP Home Edition. The C++ app is a CDialog
window.

Thanks very much for any advice!


Dave Peterson

Automating Macros for CSV files
 
I don't use C++ at all, but you can change step 2 to open that addin/workbook:

workbooks.open filename:="C:\yourpath\youraddin.xla"

Then you'll have access to the routines in that addin/workbook.



griffin_5338 wrote:

Been all over the 'net looking for an answer to this one, here goes....

I need to collect data in a C++ Net application, then from that same
application automatically (with no keys pressed) do the following:

1) Save the file as an Excel-compatible dataset (I chose CSV for its
simplicity)

2) Fire up Excel and load up the dataset into a worksheet

3) Execute a very extensive macro (over 800 lines) in Excel - this macro can
be installed as a global macro e.g. XLstart directory (see note below) as a
separate file or worksheet
(optional)

4) Leave the focus on the Excel window so the results will appear foremost
to the user

Seems simple, and I've had success with steps 1 and 2 using the
Microsoft::Office::Interop method. HOWEVER, when Excel is started from my
C++ application, none of the global macros are available. This seems to be
some kind of security limitation of global macros. Yes, I tried all four
security settings to no avail. (If you fire up Excel by itself, global
macros in XLStart are available -- but not when C++/Interop starts Excel.
Same thing when starting Excel from a VBScript.)

Is there a way to get Interop/Excel to pull in or execute a macro from a
separate worksheet?

Is it possible to get around the security limitation so global macros are
available via Interop-invoked Excel?

Is there something aside from Interop that I should use to fire up Excel and
get this macro running? One thought was to import an existing Excel document
with the macro already in it and then run the macro, but I can't find a way
to import into a worksheet.

If it helps, my configuration is: C++ Net Standard Edition, Excel 2000
Professional, all on Windows XP Home Edition. The C++ app is a CDialog
window.

Thanks very much for any advice!


--

Dave Peterson


All times are GMT +1. The time now is 01:19 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com