Skip to main content

AX2012: Open Word Application through X++

Just a small snippet to demonstrate, how we can open Microsoft word application through X++.

And this would be really significant when you want certain things to move from AX to Word for example print screen of AX forms to MS Word.

And here is the code:

Ex#1:
static void OpenWordTemplate()
{
  COM wordApp;
  COM wordDocuments;
  wordApp = new COM("word.application");
  wordDocuments = wordApp.Documents();

  wordDocuments.Open("c:\\CustomerDocument.docX");
  wordApp.visible(true);
}

Ex#2:
static void WordSaveAs()
{

  COM wordApp;
  COM wordDocuments;
  COM wordDocument;
  COM wordRng;

  wordApp = new COM("word.application");
  wordApp.visible(false);
  wordDocuments = wordApp.Documents();
  wordDocument = wordDocuments.add();
  wordRng = wordDocument.range(0,0);
  wordRng.insertafter("Customer account information");

  wordDocument.SaveAs("C:\\CustomerDocument.doc");

  wordApp.visible(true);
}


Happy Dax6ng J

Comments