Hi, you could have a look at Tools->Development tools->Wizards->COM Class Wrapper Wizard, check out how things are done in the SysExcel*, SysMicrosoftAgent or SysOutlook* classes, or create your own class in the lines of:
(Note: All error and version checking has been left out.) class MyMSWord { COM wdApp; // Word COM wdDocuments; // All documents COM wdDocument; // Current document COM wdBookmark; // Current bookmark container wdBookmarksEnum; } void new() { wdApp = new COM("Word.Application"); wdDocuments = COM::createFromObject(wdApp.Documents()); wdBookmarksEnum = this.bookmarksEnumerate(); } // Create a new document, based on template boolean documentAdd(str _template) { wdDocument = wdDocuments.Add(_template); // Add method of Word "Documents" object wdSelection = wdApp.Selection(); // The added document is now the active one return true; } // Inserting text into bookmark void bookmarkText(str _bookmark, str _text) { this.bookmarkSelect(this.bookmarkIndex(_bookmark)); // Selecting bookmark wdSelection.Text(_text); // Insert text into bookmark } // Select a bookmark by index boolean bookmarkSelect(int _bookmarkIndex) { COM cBookmarks; ; if (_bookmarkIndex <= conlen(wdBookmarksEnum)) { cBookmarks = wdDocument.Bookmarks(); wdBookmark = cBookmarks.Item(_bookmarkIndex); wdBookmark.Select(); } return (wdBookmark ? true : false); } // Find bookmark index from name int bookmarkIndex(str _name) { return confind(wdBookmarksEnum, _name); } // Enumerate bookmarks in current document container bookmarksEnumerate() { container ret; int i; COM cBookmarks; COM cBookmark; ; cBookmarks = wdDocument.Bookmarks(); for (i=1; i<=cBookmarks.Count(); i++) { cBookmark = cBookmarks.Item(i); ret = conins(ret, i, cBookmark.Name()); } return ret; } Then you should be able to do something like this: static void adbTestWordBookmarks(Args _args) { MyMSWord wd = new MyMSWord(); CustTable custTable; int n; ; //wd.Visible(1); // Make Word visible if desired. By default it's not while select custTable order by name { wd.documentAdd("C:\\Program Files\\Microsoft Office\\Templates\\1033\\Professional Fax.dot") // Create new document wd.bookmarkText("Cc", "Tech. dep."); // Bookmark wd.bookmarkText("Company", "Acme"); // Company wd.bookmarkText("Fax", custTable.TeleFax); // Fax (number) wd.bookmarkText("From", "Hal"); // From wd.bookmarkText("Pages", "1"); // Pages, could be obtained from Document object wd.bookmarkText("Subject", "Fax from Axapta"); // Subject wd.bookmarkText("To", custTable.Name); // To wd.documentSave(strfmt("Fax to customer %1.doc", custTable.AccountNum)); //or wd.documentPrint(...); wd.documentClose(); } } Looking at the vba code generated by the macro recorder in MSWord is quite useful for figuring out how to do a specific task. The vba code from MSWord can then easily be ported to Axapta. Hope this helps. Amund Wed, 25 Aug 2004 17:02:34 +0200 skrev Harry Nilsen <[EMAIL PROTECTED]>: > Hi! > > > > I have to create a Word document based on a Word template with bookmarks > from code using data from a table in Axapta. > > > > Does someone have an example of code which could help me out ? > > > > Regards, > > Harry > > > > > > [Non-text portions of this message have been removed] > > > > Yahoo! Groups Sponsor > ADVERTISEMENT > > Yahoo! Groups Links > > To visit your group on the web, go to: > http://groups.yahoo.com/group/development-axapta/ > > To unsubscribe from this group, send an email to: > [EMAIL PROTECTED] > > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. ------------------------ Yahoo! Groups Sponsor --------------------~--> Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar. Now with Pop-Up Blocker. Get it for free! http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/saFolB/TM --------------------------------------------------------------------~-> Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/development-axapta/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/