Can you call macros in one spreadsheet from another workbook using C#/.Net?

Discussion in 'Automated Trading' started by AliJay, Feb 9, 2020.

  1. AliJay

    AliJay

    For some years I have been running two ActiveX Excel spreadsheets in VBA simultaneously and have been able to run one spreadsheet as a kind of slave from the other using the "Application.Run" function eg.

    Application.Run "OtherWorkbook.xls!Sheet1.RunMacro"

    However just recently I have needed to convert the VBA macros to C#/.Net which I know very little about.

    Is there a function in C#/.Net whereby I can replicate the Application.Run function? In other words initiate a macro from another worksheet.

    Any help would be very much appreciated....
     
  2. You can call .NET from Excel (via COM), I don't understand the question.
     
  3. AliJay

    AliJay

    Hi, I am really sorry for not being clearer. Thank you for trying to understand. To be honest I am a trader not a programmer so I apologize for the ambiguity.


    I have two separate excel spreadsheets that run at the same time. They run continuously during market hours monitoring the markets. One is more of a "master" in that it runs the slave. These Spreadsheets have, up to now, used VBA but there is a necessity to change and run the spreadsheets via .Net. My question is how do you call a macro to start a run in another spreadsheet using .Net?


    In VBA I have used the Application.Run function and defined the other spreadsheet and the specific macro that I want to run. I am hoping to understand how to do this using .Net.


    If you could help I would be very grateful .... thank again in advance.
     
  4. schizo

    schizo

    https://www.ablebits.com/office-addins-blog/2015/12/08/excel-reference-another-sheet-workbook/
     
    AliJay likes this.
  5. AliJay

    AliJay

    Thanks so much - let me take a look at that ....
     
  6. AliJay

    AliJay

    That article is how to reference cells from one worksheet to another. I am attempting (and so far failing) to call a macro to run in worksheet A from a master in worksheet B. If you could point me in the right direction I would be indebted.
     
  7. schizo

    schizo


     
    Last edited: Feb 10, 2020
    AliJay likes this.
  8. AliJay

    AliJay

    Thanks Schizo for your help it is very much appreciated. I am trying find a way of calling the macro from within another worksheet using .net.

    I will persist and report back - thanks everyone.
     
  9. schizo

    schizo

    AliJay likes this.
  10. AliJay

    AliJay

    REALLY appreciate your help Schizo ..... have a great evening.
     
    #10     Feb 10, 2020