Navision and Ms-Word

Hello, Where can i find examples of code C / AL to transfer data from a table in a document Microsoft Word. Indeed users want to write some mail to the customers under Word .I thank you for your help. Benoît B.Durand

Use Excel. Very simply. Much simpler than Word. I’m trying to find anything about this about 1 year but without any results. Business Applications Programmer Sertified Navision Developer SIA “Sintegra” Latvia

If you send me your e-mail, i can send you an exemple on Word and Excel. JML

So that all my benefit, below is an example of a mail merge that we use here. It is fairly straight forward IMHO. It is designed to print out a word document created by Mail Merge, then the associated Sales Invoice. A note is also placed into the Comment Line table: //CODInvoice CustLdgrEntry.TESTFIELD(“Document Type”,CustLdgrEntry.“Document Type”::Invoice); IF CustLdgrEntry.“Remaining Amount” <= 0 THEN EXIT; CompanyInfo.GET; CompanyInfo.CALCFIELDS(“Collection Manager Name”,CompanyInfo.“Collection Manager E-Mail”); Cust.GET(CustLdgrEntry.“Customer No.”); TemplateName := CompanyInfo.“COD Invoice Path”; CREATE(wdApp); wdDoc := wdApp.Documents.Add(TemplateName); wdApp.ActiveDocument.Fields.Update; wdApp.Visible := FALSE; // Set Company Address wdRange := wdApp.ActiveDocument.Fields.Item(1).Result; wdRange.Text := CompanyInfo.Address; // Set Company City State, Zip wdRange := wdApp.ActiveDocument.Fields.Item(2).Result; wdRange.Text := CompanyInfo.City + ', ’ + CompanyInfo.State + ’ ’ + CompanyInfo.“ZIP Code”; // Set Company Phone wdRange := wdApp.ActiveDocument.Fields.Item(3).Result; wdRange.Text := CompanyInfo.“Phone No.”; // Set Company Toll-Free Phone wdRange := wdApp.ActiveDocument.Fields.Item(4).Result; wdRange.Text := 'Toll Free ’ + CompanyInfo.“Toll Free Phone No.”; // Set Company Fax wdRange := wdApp.ActiveDocument.Fields.Item(5).Result; wdRange.Text := ‘Fax ’ + CompanyInfo.“Fax No.”; // Set Collection Manager E-mail wdRange := wdApp.ActiveDocument.Fields.Item(6).Result; wdRange.Text := CompanyInfo.“Collection Manager E-Mail”; // Set Date wdRange := wdApp.ActiveDocument.Fields.Item(7).Result; wdRange.Text := FORMAT(TODAY,0,’ <Day,2>, '); // Set Customer Name wdRange := wdApp.ActiveDocument.Fields.Item(8).Result; wdRange.Text := Cust.Name; // Set Customer No. wdRange := wdApp.ActiveDocument.Fields.Item(9).Result; wdRange.Text := Cust.“No.”; // Set Customer Address wdRange := wdApp.ActiveDocument.Fields.Item(10).Result; wdRange.Text := Cust.Address; // Set Customer City, State Zip wdRange := wdApp.ActiveDocument.Fields.Item(11).Result; wdRange.Text := Cust.City + ', ’ + Cust.State + ’ ’ + Cust.“ZIP Code”; // Set Past Due Balance wdRange := wdApp.ActiveDocument.Fields.Item(12).Result; wdRange.Text := StringFunctions.FormatCurrency(CustLdgrEntry.“Remaining Amount”); // Set Invoice No. wdRange := wdApp.ActiveDocument.Fields.Item(13).Result; wdRange.Text := CustLdgrEntry.“Document No.”; // Set Collection Managers Phone Number wdRange := wdApp.ActiveDocument.Fields.Item(14).Result; wdRange.Text := CompanyInfo.“Collection Manager Phone No.”; // Set Collection Manager Name (Script Font) wdRange := wdApp.ActiveDocument.Fields.Item(15).Result; wdRange.Text := CompanyInfo.“Collection Manager Name”; // Set Collection Manager Name wdRange := wdApp.ActiveDocument.Fields.Item(16).Result; wdRange.Text := CompanyInfo.“Collection Manager Name”; // Set Company Name wdRange := wdApp.ActiveDocument.Fields.Item(17).Result; wdRange.Text := CompanyInfo.Name; PrintBackground := FALSE; wdApp.PrintOut(PrintBackground); SaveChanges := FALSE; wdApp.Quit(SaveChanges); CLEAR(wdApp); CLEAR(wdDoc); CLEAR(wdRange); SalesInvHeader.SETRANGE(“No.”,CustLdgrEntry.“Document No.”); REPORT.RUN(REPORT::“Sales Invoice (Posted)”,FALSE,TRUE,SalesInvHeader); InsertCustComments(Cust,‘COD Invoice ’ + CustLdgrEntry.“Document No.” + ’ Letter’); SetCustNextActivityDate(Cust); Bill Benefiel Manager of Information Systems Overhead Door Company billb@ohdindy.com (317) 842-7444 ext 117

Maybe this helps, You need to create a Template for Mail Merge with FieldNames as indicated in the CASE statement. With this sample you can create a unique routine to put fields on different doc files. You only need to indicate what template you are going to use. This sample saves the document, but you can print it, … OBJECT Codeunit 50000 Word sample PROPERTIES TableNo=18; OnRun=VAR l_autWordApp : Automation ‘Microsoft Word 8.0 Object Library’.Application; l_autWordDoc : Automation ‘Microsoft Word 8.0 Object Library’.Document; l_autWordRange : Automation ‘Microsoft Word 8.0 Object Library’.Range; l_txtDotName : Text[250]; l_txtDocName : Text[250]; l_intLoop : Integer; BEGIN CLEAR(l_autWordApp); CLEAR(l_autWordDoc); CLEAR(l_autWordRange); CALCFIELDS(“Balance (LCY)”); IF “Balance (LCY)” < 1000 THEN EXIT; CREATE(l_autWordApp); l_txtDotName := ‘C:\Documents and Settings\JSL\Mis documentos\Test.dot’; // Template l_txtDocName := ‘C:\Documents and Settings\JSL\Mis documentos\Test.doc’; // Document name to save l_autWordDoc := l_autWordApp.Documents.Add(l_txtDotName); l_autWordApp.ActiveDocument.Fields.Update; FOR l_intLoop := 1 TO l_autWordApp.ActiveDocument.Fields.Count DO BEGIN l_autWordRange := l_autWordApp.ActiveDocument.Fields.Item(l_intLoop).Result; CASE COPYSTR(UPPERCASE(l_autWordRange.Text), 2, STRLEN(l_autWordRange.Text) - 2) OF ‘NAME’: l_autWordRange.Text := Name; ‘ADDRESS’: l_autWordRange.Text := Address; ‘CITY’: l_autWordRange.Text := City; ‘BALANCE’: l_autWordRange.Text := FORMAT(“Balance (LCY)”, 0, 0); END; END; l_autWordApp.Visible := TRUE; l_autWordApp.ActiveDocument.Fields.Unlink; l_autWordDoc.SaveAs(l_txtDocName); CLEAR(l_autWordApp); CLEAR(l_autWordDoc); CLEAR(l_autWordRange); END; Regards, Jesús Soage Edited by - JSOAGE on 2001 Oct 29 09:41:57