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
0
Comments
Change youre code
From
IF NOT CREATE(wdApp,FALSE) THEN
TO
IF NOT CREATE(wdApp,TRUE) THEN
Not tested but i maybe it works! :?
webmaster@amargosasun.de
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
UK