Create word document from AX
Very simple … the use fo COM object isn’t the best way, but in many case could be a quick solution.
static void CreateWordDocument(Args _args)
{
Filename template;
CustTable custtable;
COM word;
COM documents;
COM document;
COM bookmarks;
COM bookmark;
COM range;
COM selection;
void processBookmark(str _name, str _value)
{
if(!bookmarks.exists(_name))
return;
bookmark = bookmarks.item(_name);
range = bookmark.range();
range.insertAfter(_value);
};
#define.Word(‘Word.Application’)
#define.template(@’c:\temp\letter.dotx’)
//CustTable = CustTable::find(‘50200805’);
try
{
word = new COM(#Word);
}
catch
{
if(word == null)
throw error(“Microsoft Word is not installed”);
}
documents = word.documents();
document = documents.add();
selection = word.Selection();
while select firstonly100 custtable
{
selection.typeText(custtable.AccountNum + ‘ – ‘ + custtable.name() + ‘\r\n’);
}
//bookmarks = document.bookmarks();
//processBookmark(‘Customer’, custtable.name());
word.visible(true);
}
This was originally posted here.

Like
Report
*This post is locked for comments