Add/Run macro programatically OLE error
I'm trying to add/run a macro programatically via ole. I have a test file
named formatreports.bas:
Attribute VB_Name = "FormatReports"
Sub A1All(oWorkbook As Workbook)
Dim x As Integer
For x = oWorkbook.Sheets.Count To 1
Sheets(x).Activate
Sheets(x).Range("A1").Select
Next x
End Sub
In my app, I do this:
TRY
loExcelApp.VBE.ActiveVBProject.VBComponents.Import (
goApp.cCurrentPath + "formatreports.bas" )
loExcelApp.Run( "A1All", loExcelApp )
CATCH TO loErr
ENDTRY
The import line works fine, but when I invoke the macro, I get an error
like:
"OLE IDispatch exception code 0 from Microsoft Office Excel: The macro
'A1All' cannot be found..."
I also tried "FormatReport.A1All" for the macro argument, but I get the
same error.
What am I missing here?
Thanks,
Woody
|