word automation from a report

knight
Member Posts: 45
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
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
-
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.de0 -
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
UKAjay Jain
UK0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions