web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Simple AX / Create word document from AX

Create word document from AX

Daniele Ferraretto Profile Picture Daniele Ferraretto

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.

Comments

*This post is locked for comments