My scenario is as below .
1. I am opening an MXD from a standalone exe file.This is fine, the MXD is getting opened successfully.
2. I have developed an ArcMap extension and it it's Startup event, I want to call the the VBA macro inside the MXD.
3. The problem is here, I get an error "Error running VBA code : Error in macro"
4. The macro works fine manually, I means I open the MXD and run the macro manually, it runs fine.
Code to tun the macro is as below:
private bool RunMyMacro(IApplication pApplication)
IMxDocument pMxDoc = pApplication.Document as IMxDocument;
IMapDocument pMapDoc = pMxDoc as IMapDocument;
//check the name of the MXD. IF it is what we wantm run the macro
if (String.IsNullOrEmpty(pMapDoc.DocumentFilename) == false)
//run the macro
IVbaApplication pVBAApps = pApplication as IVbaApplication;
pVBAApps.RunVBAMacro("Project", "ThisDocument", "Trace_Transformers_LV", null);
catch (Exception ex)
string errMsg = ex.Message;
string stkTrace = ex.StackTrace;
//Code of StartUp event of an extension
public void Startup(ref object initializationData)
IApplication pApps = initializationData as IApplication;
Earlier, the macro was getting called from the EXE it self and it works fine .However, after running fine for a week or so, it starts throwing an error. To work around this, I'm trying to call the macro from the extension, but it is also not working.Even a simple HelloWorld macro is not getting called from the extension.
I would really appreciate any help on this issue.
The following link from Microsoft might be of some help:
How to dynamically add and run a VBA macro from Visual Basic
Just as an FYI, ESRI no longer supports VBA. Support for VBA stopped at ArcGIS version 10.0. Please migrate your VBA customizations to ArcObjects .NET (VB.NET or C#). The link below shows how this can be done.