Excel Auto_macro with actxserver problem

4 views (last 30 days)
John
John on 22 Mar 2011
Hi,
I have been using actxserver to write to excel for years but now I need to use if to modify a macro enabled .xlsm file and run the macro. I have followed examples on here to run a simple macro but cannot figure out how to use it for my situation.
My .xlsm file has an automatic macro "Workbook_Open" that runs on opening and brings up a userform that requests 4 file locations and a button click. How can I pass these parameters, especially the button click, to the userform and ultimately the macro upon opening? The 4 file locations are also stored in a range in the first worksheet so I can probably modify them with Workbook.Range.Value
I have tried:
ExcelApp = actxserver('Excel.Application');
ExcelApp.Visible = 1;
ExcelFile=ExcelApp.Workbooks.Open(fullfile(pwd,filename));
ExcelApp.Run('ThisWorkbook.Workbook_Open','OK_Pressed');
and I have also replaced the last line with:
ExcelApp.Workbooks.Item(Filename).RunAutoMacros(1);
but MATLAB either reports as busy or has errors such as "Invoke Error, Dispatch Exception"
My macro is specified below:
Private Sub Workbook_Open()
Set DataSheet0 = ThisWorkbook.Worksheets.Item("Sheet1")
frmProcess.Show
If (OK_Pressed) Then 'this button click is from the user form "frmProcess"
Call FREZCONV_Main
Else
Call FREZCONV_TidyUp(2)
End If
ThisWorkbook.Close
End Sub
Any help with understanding what I'm doing wrong would be greatly appreciated.
John

Answers (0)

Categories

Find more on Parallel for-Loops (parfor) in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!