Running an Excel macro from another workbook

Running an Excel macro from another workbook

By : Constantine Stupakev
Date : November 22 2020, 04:01 AM
should help you out I have a subroutine that opens a workbook containing a macro. I then want to run that macro. My code looks like this:
code :
Application.Run ("'Name of the book'!ModuleName.SubName")

Share : facebook icon twitter icon
running excel macro from another workbook

running excel macro from another workbook

By : user1980915
Date : March 29 2020, 07:55 AM
I hope this helps . I have a macro that is on a server. I need to be able to run it from different workstations that connect to this server. , I think your syntax is missing the single quote characters:
code :
Application.Run ("'L:\database\lcmsmacro\macro1.xlsm'!macro_name") 
Application.Run ("'L:\database\lcmsmacro\macro1.xlsm'!macro_name","param1","param2") 
Running an Excel Macro via C#: Run a macro from one workbook on another?

Running an Excel Macro via C#: Run a macro from one workbook on another?

By : Isaac Nattan
Date : March 29 2020, 07:55 AM
may help you . I found a solution that I'd like to share. First, I removed the bit where I opened Worksheet01. I then had my automated script save the .CSV to My Documents. I then used the code I had to open Worksheet01 to open the downloaded file. The key thing at this point is that Worksheet01 is in the Documents folder with Worksheet02. Lastly I used the code to run the macro from Worksheet01, which runs on Worksheet02.
code :
    public void WebTest_CodedStep()
        // Object for missing (or optional) arguments.
        object oMissing = System.Reflection.Missing.Value;

        // Create an instance of Microsoft Excel
        Excel.ApplicationClass oExcel = new Excel.ApplicationClass();

        // Make it visible
        oExcel.Visible = true;

        // Define Workbooks
        Excel.Workbooks oBooks = oExcel.Workbooks;
        Excel._Workbook oBook = null;

        // Get the file path
        string path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
        path = path + "\\Worksheet02.csv";

        //Open the file, using the 'path' variable
        oBook = oBooks.Open(path, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing,  oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);

        // Run the macro, "First_Macro"
        RunMacro(oExcel, new Object[]{"Worksheet01.xlsm!First_Macro"});

        // Quit Excel and clean up.
        oBook.Close(false, oMissing, oMissing);
        System.Runtime.InteropServices.Marshal.ReleaseComObject (oBook);
        oBook = null;
        System.Runtime.InteropServices.Marshal.ReleaseComObject (oBooks);
        oBooks = null;
        System.Runtime.InteropServices.Marshal.ReleaseComObject (oExcel);
        oExcel = null;

        //Garbage collection

    private void RunMacro(object oApp, object[] oRunArgs)
        oApp.GetType().InvokeMember("Run", System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.InvokeMethod, null, oApp, oRunArgs);
Running Excel macro in a specific workbook fails from C#

Running Excel macro in a specific workbook fails from C#

By : NarcoOtdel
Date : March 29 2020, 07:55 AM
like below fixes the issue Wrap the workbook name in quotes
code :
string macro = string.Format("'{0}'!{1}", workbook.Name, macroName);
Running an Excel macro on a different workbook

Running an Excel macro on a different workbook

By : magsoft
Date : March 29 2020, 07:55 AM
hope this fix your issue I have since solved the issue.
The issue occuring was as a result of trying to run an "xlsm" format macro on a different document. Running macros on another workbook is only possible with Microsoft Office Excel Binary Worksheet (xlsb format). If you're facing the same issue - use an xlsb to save the macros in, not xlsm.
code :
/// <summary>
/// Run a macro from an xlsb file on another excel file
/// </summary>
/// <param name="ExcelFile">The excel file to run the macro on</param>
/// <param name="MacroFileLocation">The xlsb file the macro is saved in</m>
/// <param name="Macro">The macro name to run (e.g. Module1.Example)</param>
static void Test(string ExcelFile, string MacroFileLocation, string Macro)
    Application xlApp = new Application(); //Excel app
    Workbook xlWbk = null;
        xlWbk = xlApp.Workbooks.Open(ExcelFile);

        string MacroCommand = "'" + MacroFileLocation + "'!" + Macro;
        //Clean up
        if (xlWbk != null)
                //Couldn't save - consider alerting user


        xlWbk = null;
        xlApp = null;
Running Excel Add-In Macro Based on Workbook Events

Running Excel Add-In Macro Based on Workbook Events

By : user2312192
Date : March 29 2020, 07:55 AM
will be helpful for those in need Update: I managed to make it work using Application Events. The idea is to create a class module that can then be assigned the Application.
Here are some useful links that helped me: http://www.cpearson.com/excel/AppEvent.aspx
Related Posts Related Posts :
  • Delete a UserForm and add a New UserForm in Excel VBA
  • Keypress about not allowing testers inputing 2 digits in a textbox in vba
  • VBA listobject lookup function fast
  • Excel VBA For Loop to Duplicate Data
  • How do I change the background image of a chart in vba?
  • VBA - Loop through files in a folder AND copy single cells as well as a range, if condition is met
  • Screenshotting Google Maps and Pasting into Excel Document VBA
  • Comments split by page break
  • Data Manipulation / Dissecting
  • Convert multi column table to single columns with repeat pattern
  • IF statement to trigger specific conditional formatting?
  • Offsetting a date based on time in excel using if and function
  • Search a copied value MACRO
  • Code to delete rows containing a search string skips some rows with the string
  • Open file in vba Excel environment
  • How can i count the frequency of those of a number showing from a countif but only once?
  • Excel - check values in multiple columns and return the sum of a third column
  • VBA userform: application-defined or object-defined error
  • Delete without warning any sheet for which the name contains the word "sheet"
  • Csv file is not aligned correctly in excel
  • Filter one column and count values in other
  • vba excel listobject HeaderRowRange
  • how to add text box/shape around each cell in the selection?
  • Determining Last Names in excel from a range of full names in varying formats
  • Read Column A, insert rows based on pattern
  • If 1 or both columns has word, then enter text
  • SUM of VLOOKUP functions meeting criteria in Excel
  • Extract text using css selector
  • How to use Excel::Writer::XLSX to create a table where inserting a row copies a column's formula?
  • Change Chart Colours (bar) Based on Source Cell (using conditional formatting and VBA)
  • Web query throws error: import currenturl matches no exports. Did you miss a module reference?
  • VLookUp value to another worksheet
  • Writing a loop that has multiple criteria
  • Paste a copied data range in all open workbooks using a loop
  • Use Excel-VBA to colour a range y if value is certain number is placed AND colour range x if value is certain number is
  • Getting meta property from a URL
  • Power Query - Create date from datenumber and time column
  • Colour a cell if a certain number is entered
  • vba target.count=1 error when selecting all
  • Excel selecting special condition
  • Searching through list of random files in directory and renaming files based on Cell Value
  • Avoid counting unfiltered results using COUNTIFS formula
  • Excel macro saving sheet as pdf to sharepoint to location dependent on input in new folder
  • Power Query - replacing text in a new column
  • Check availability of folder/files
  • Souble Loop sheets and cells
  • getting compiler error (invalid identifier)
  • Excel Formula - Match substrings of List to List
  • Trigger same macro with different command button with Button properties
  • Laravel Export Excel doesn't return an excel file
  • Put timestamp when a checkbox is ticked or unticked
  • Index was out of range must be less than or negative
  • VBA Saving delay after data entry
  • Sort cells that have the same date but different time
  • VBA - Delete all rows that do not contain at least 1 highlighted cell
  • Access password blocked sheet - Excel
  • Excel not displaying text when html:color applied via XSLT
  • VBA How to programmatically use conditional formatting and have it apply to numbers only
  • SUM lots of half hourly data into a separate list
  • OpenXML Pagesetup (PrintOptions, pageMargins, Orientation, headerfooter) Error
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org