Dynamics AX
  RSS Feed  LinkedIn  Twitter
Want to turn you're data into a true asset? Ready to break free from the report factory?
Ready to gain true insights that are action focused for truly data informed decisions?
Want to do all of this across mutliple companies, instances of Dynamics and your other investments?
Hillstar Business Intelligence is the answer then! (www.HillstarBI.com)

Hillstar Business Intelligence for Microsoft Dynamics AX and NAV on Mobile, Desktop, Tablet


Let us prove to you how we can take the complexity out of the schema and truly enable users to answer the needed questions to run your business! Visit Hillstar Business Solutions at: www.HillstarBI.com

Friday, May 23, 2008

Calling an Excel Macro from X++

All, recently I needed to know how to call an Excel Macro from X++. This is not something that is widely published anywhere on the web, and something I had to figure out.

It's actually not that hard, and the best help was looking at how I had done it before in .Net.

So here is the code example:


SysExcelApplication ExcelApp;
SysExcelWorkbooks WorkBooks;
SysExcelWorkbook WorkBook;
SysExcelWorksheet Worksheet;
;


ExcelApp = SysExcelApplication::construct();
ExcelApp.displayAlerts(true);
ExcelApp.visible(true);

ExcelApp.workbooks().open("SomeExcelFile.xls");

Workbook = ExcelApp.workbooks().item(1);
Worksheet = Workbook.worksheets().itemFromName("WorkSheetName");

ExcelApp.comObject().Run("SomeMacro"); // The Call to run a Macro


Of course there is a lot more you can do, but basically any Excel based class has a .comObject() at which you can further extend and make Excel Interop COM calls via, that go beyond what is coded for in the SysExcel Class framework.

Check back soon!

"Visit the Dynamics AX Community Page today!"


Labels: , , , , , ,

5 Comments:

Blogger Stephen said...

Useful post!
Is it possible to open a workbook whilst selecting the enable macros option from AX code?

1:19 AM  
Anonymous Anonymous said...

Would it be possible to transfer a worksheet to another workbook in AX?

10:19 AM  
Blogger AML said...

Hi,

I want to insert new row in excel using macro in x++. I used tried this code but i got error. I don't know how to do this, please help me.. thanks.

This is the code:
ExcelApp.comObject().Run("ActiveCell.EntireRow.Insert");

please help me on how to achieve this.. more power..

Regards,
AML

12:05 AM  
Blogger AML said...

Hi,

Is this correct?

ExcelApp.comObject().Run("ActiveCell.EntireRow.Insert");

Regards,
AML

12:08 AM  
Anonymous Anonymous said...

Try to use this instead:

Com excelRange, entireRow;
;

excelRange = xlsWorkSheet.cells().range(strfmt("%1%3:%2%3","A","A",18)).comObject();

entireRow = excelRange.entireRow();
entireRow.insert();

7:08 AM  

Post a Comment

Links to this post:

Create a Link

<< Home


Copyright 2005-2011, J. Brandon George - All rights Reserved