word automation from a report

knightknight Member Posts: 45
edited 2002-12-12 in Navision Financials
I want to run a report that will dump certain Job information straight into a Word Template for each record that the report runs through. To do this I am using the following Word Automation Globals:

Name DataType Subtype Length
wdApp Automation 'Microsoft Word 9.0 Object Library'.Application
wdDoc Automation 'Microsoft Word 9.0 Object Library'.Document
wdRange Automation 'Microsoft Word 9.0 Object Library'.Range

The example code I am using is as follows:

CLEAR(wdApp);
CLEAR(wdDoc);
CLEAR(wdRange);
IF NOT CREATE(wdApp,FALSE) THEN
ERROR('Could not start WinWord as an Automation Server');
wdApp.Visible := TRUE;
TemplateName := '"C:\Documents and Settings\Default\Application Data\Microsoft\Templates\Feedback Merge.dot"';
wdDoc := wdApp.Documents.AddOld(TemplateName);

wdRange := wdApp.ActiveDocument.Fields.Item(vPos).Result;
wdRange.Text := 'Sample Text';
wdApp.ActiveDocument.Fields.Unlink;
wdApp.Visible := TRUE;
___________________

So far this code works fine, the only catch is it places each record it passes through into a separate Word Document. Is it at all possible through Word Automation, to get it to just keep copying the template as extra pages within the same document, rather than creating a new Document each time?

Your help is appreciated, thanks.

Simon Kuldin
Information Outlook

Comments

  • AmargosaAmargosa Member Posts: 2
    Hi

    Change youre code ;)

    From
    IF NOT CREATE(wdApp,FALSE) THEN

    TO
    IF NOT CREATE(wdApp,TRUE) THEN

    Not tested but i maybe it works! :?
    Ben the Amargosa Sun
    webmaster@amargosasun.de
  • ajayjainajayjain Member Posts: 119
    hi
    try this code

    wdSel Automation 'Microsoft Word 9.0 Object Library'.Selection

    create(wdApp);
    wdApp.visible:=true;
    TemplateName := '"C:\Documents and Settings\Default\Application Data\Microsoft\Templates\Feedback Merge.dot"';
    wdDoc:=wdApp.Documents.AddOld(TemplateName);
    wdSel:=wdApp.Selection;
    wdSel.TypeText:='This is First Line';
    wdSel.TypeParagraph;
    wdSel.TypeText:='This is Second Line';
    wdSel.TypeParagraph;
    wdSel.TypeParagraph;
    wdSel.TypeText:='This is Third LIne';

    ajay jain
    UK
    Ajay Jain
    UK
Sign In or Register to comment.