AnsweredAssumed Answered

Can't run VBA macro from the extension.

Question asked by sanjayjadhav on Jul 23, 2014
Latest reply on Oct 14, 2015 by SEria-esristaff



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)
                    if (pMapDoc.DocumentFilename.Contains("MyMXDName"))
                        //run the macro
                        IVbaApplication pVBAApps = pApplication as IVbaApplication;
                        pVBAApps.RunVBAMacro("Project", "ThisDocument", "Trace_Transformers_LV", null);
                        return false;
                return true;
            catch (Exception ex)
                string errMsg = ex.Message;
                string stkTrace = ex.StackTrace;
                return false;

//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.