none
Execute Macro using OPEN XML code RRS feed

  • Question

  • Hi All,

    I am using OPEN XML to export data into existing excel template from the database but I can't find the way to execute macro (which is already existing in a excel template) through OPEN XML code. If anyone has ever executed macro through the OPEN XML code or knows how to execute it then kindly let me know the way. I am using C# as a programming language.

     

    Thanks in advance,

    S.Bah

    • Moved by Aspen VJ Monday, May 30, 2011 6:01 AM (From:Visual C# General)
    Friday, May 27, 2011 5:16 AM

All replies

  • Hi S.Bah,

    I am afraid you we can't add or execute macro via open xml, please take a look at the 27th item of open xml FAQ:http://social.msdn.microsoft.com/Forums/en-US/oxmlsdk/thread/19032efe-80af-4a16-b954-1f5a6d2f2236/#x_Q26 which points out:

    Open XML SDK doesn’t support macro. It is a collection of classes that let you create and manipulate Open XML documents. 

    In order to execute macro, we must have the parent application that supports it such as word. Open XML is not menat to do any calculations. It is for reading and writing into XML files (Office 2007 /2010 documents are XML based), and even we do not have to install the Office application on the computer.

    Thank you for your understanding.

    Best Regards,

     


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Edited by Bruce Song Wednesday, June 1, 2011 6:51 AM
    Tuesday, May 31, 2011 3:11 AM
  • Hi Bruce,

    Thanks for your reply. As per your reply, I understood that we can't execute the macro(s) using OPEN XML. But is there any other way to execute the macro(s) (which are existing in excel templates) without using interops?

    Thanks & Regards,

    S.Bah

    Tuesday, May 31, 2011 5:50 AM
  • Hi S.Bah,

    Without Office PIA, we can't execute the macro in the template via C#. We must add the interop reference to the project.

    Hope you can figure it out.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, June 1, 2011 6:56 AM
  • Hi Bruce,

    Thanks for your quick reply. Here, the problem is that we can't use PIAs because they are giving security problems. That's why we switched to OPEN XML but now it seems that OPEN XML also has limitation in terms of Macro execution.

    Regards,

    S.Bah

    Monday, June 6, 2011 4:48 AM
  • Hi S.Bah,

    Yes, it is the limitation in terms of Macro execution. Here is another thread talking about this problem:

    http://social.msdn.microsoft.com/Forums/en/oxmlsdk/thread/6780dbbd-2a99-4929-86ae-a75f541743ad

    Some experts pointed out the Excel calculation services, I am not sure whether you will take it into consideration.

    Best Regards,

     


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, June 7, 2011 12:54 PM
  • Hi Bruce,

    Thanks for your kind reply. I think if that's the limitation then I can use Powershell to run the macro and I will use OPENXML to populate the data in excel.

    I think this will work. Please provide your inputs if you have any better idea.

    Regards,

    S.Bah

     

    Monday, June 13, 2011 7:37 AM
  • If you need to run a specific macro you can have that module under "This Workbook" Workbook_Open.

    Put the excel file under XLSTART folder in program files\microsoft office\office (10/11/12/14)\XLSTART 

     

    And from you xml call open excel and you are good to go.

    Monday, July 25, 2011 6:09 PM