We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Opening an excel file which contains macro

How to open an excel file using Syncfusion APIs, if the file contains macros?


7 Replies

YG Yavanaarasi G Syncfusion Team July 15, 2008 05:30 AM UTC

Hi Venkatesan,

Thank you for your interest in Syncfusion products.

Normally an excel file is open with XlsIO using the below code snippet. The similar way is used to open the file that contains macros. It has no difference. But currently we have support only for preserving macros from the template. XlsIO does not have any support for manipulating/running macros at runtime.

Here is the code snippet:

[C#]
//Step 1 : Instantiate the spreadsheet creation engine.
ExcelEngine excelEngine = new ExcelEngine();
//Step 2 : Instantiate the excel application object.
IApplication application = excelEngine.Excel;
//Open an existing spreadsheet
IWorkbook workbook = application.Workbooks.Open(@"..\..\VBATemplate.xls");


Please let me know if you have any other concerns.

Regards,
G.Yavana



AD Administrator Syncfusion Team July 15, 2008 03:25 PM UTC

The only difference, the way I open the file is that file name not starting with the '@' symbol. I even put this command

workbook.DisableMacrosStart = true;

Is there a way to ignore that initial popup message comes for enable/disable macro and still open the file?



YG Yavanaarasi G Syncfusion Team July 16, 2008 04:33 AM UTC

Hi Venkatesh,

The macros are enabled by default while opening spreadsheet and it can be disabled by DisableMacrosStart property in XlsIO. Also you can remove macros using the following code snippet:


myWorkBook.Application.SkipOnSave = SkipExtRecords.Macros;


Please try this and let me know if this helps.

Regards,
G.Yavana




MH Mangesh Hirave March 18, 2016 02:40 PM UTC

Hi,
I am working with macro enabled template (xltm) however, once opened at the time of saving the file I need to remove or at least disable the macros. I noticed the WordDocument has RemoveMacros() method available. Is there any similar functionality available for Excel? The follwing didn't work for me. The macros were still copied.
myWorkBook.Application.SkipOnSave = SkipExtRecords.Macros;



IN Ishwarya Narayanan Syncfusion Team March 22, 2016 05:48 AM UTC

 

Hi Mangesh,

 

Sorry for the delay.

 

As you have created an incident with similar query, the response for this query will be updated in that incident. You can follow up the incident for further clarification regarding this query.


Please let us know if you have any concerns.

Regards,
Ishwarya N



EM Emmett Miller March 5, 2021 11:36 AM UTC

Does XlsIO now support for manipulating/running macros at runtime? Will it support it in the future if not?




SK Shamini Kiruba Sobers Syncfusion Team March 8, 2021 08:39 AM UTC

Hi Emmett, 

Currently, XlsIO cannot run macros and we have no immediate plans to support it. But we have support for creating and editing macros. Kindly refer the following UG link. 

Regards, 
Shamini 


Loader.
Live Chat Icon For mobile
Up arrow icon