Word Automation with searching in Word Header?

elwin68
Member Posts: 153
Hello,
Our customer can make Templates in Word 2007 which can be stored in NAV2009SP1.
With Word Automation the template can be filled with NAV information. This is done by searching for specific strings and replacing them with the proper NAV information.
Unfortunately the search and replace process was not working in the header and footer.
We have made some changes so the searching and replacing process and now it works in the header and footer as well.
Unfortunally there is a side effect.
When the Word Document is shown the header is shown too, even if it contains no data. This is a problem when using special page formats without headers.
When opening the header in Word and closing it again the header disappears.
Tests show that by using the Range.Find in the header, the header is shown in the Word document, even if it contains no data.
I have added a codeunit to reproduce the problem.
Thanks in advance.
Our customer can make Templates in Word 2007 which can be stored in NAV2009SP1.
With Word Automation the template can be filled with NAV information. This is done by searching for specific strings and replacing them with the proper NAV information.
Unfortunately the search and replace process was not working in the header and footer.
We have made some changes so the searching and replacing process and now it works in the header and footer as well.
Unfortunally there is a side effect.
When the Word Document is shown the header is shown too, even if it contains no data. This is a problem when using special page formats without headers.
When opening the header in Word and closing it again the header disappears.
Tests show that by using the Range.Find in the header, the header is shown in the Word document, even if it contains no data.
I have added a codeunit to reproduce the problem.
OBJECT Codeunit 60100 Test Word Automation { OBJECT-PROPERTIES { Date=17-05-11; Time=[ 9:19:47]; Modified=Yes; Version List=TEST; } PROPERTIES { OnRun=VAR wdAppGaut@1000000003 : Automation "{00020905-0000-0000-C000-000000000046} 8.4:{000209FF-0000-0000-C000-000000000046}:'Microsoft Word 12.0 Object Library'.Application"; wdDocGaut@1000000002 : Automation "{00020905-0000-0000-C000-000000000046} 8.4:{00020906-0000-0000-C000-000000000046}:'Microsoft Word 12.0 Object Library'.Document"; wdFindGaut@1000000001 : Automation "{00020905-0000-0000-C000-000000000046} 8.4:{000209B0-0000-0000-C000-000000000046}:'Microsoft Word 12.0 Object Library'.Find"; wdSelectionGaut@1000000000 : Automation "{00020905-0000-0000-C000-000000000046} 8.4:{00020975-0000-0000-C000-000000000046}:'Microsoft Word 12.0 Object Library'.Selection"; wdView@1000000010 : Automation "{00020905-0000-0000-C000-000000000046} 8.4:{000209A5-0000-0000-C000-000000000046}:'Microsoft Word 12.0 Object Library'.View"; Field@1000000005 : Text[30]; Value@1000000006 : Text[30]; Value1@1000000007 : Integer; Value0@1000000008 : Integer; Counter@1000000004 : Integer; ReplaceAll@1000000009 : Integer; Text001@1000000011 : TextConst 'ENU=With searching in Header;NLD=Met zoeken in koptekst'; WithSearching@1000000012 : Boolean; BEGIN WithSearching := FALSE; IF CONFIRM(Text001) THEN WithSearching := TRUE; IF ISCLEAR(wdAppGaut) THEN CREATE(wdAppGaut, TRUE, TRUE); wdAppGaut.Visible(TRUE); //Show Word wdDocGaut := wdAppGaut.Documents.Add; //Add New Document wdSelectionGaut := wdAppGaut.Selection; Value0 := 0; Value1 := 1; Field := 'Field'; Value := 'Value'; ReplaceAll := 2; IF WithSearching THEN BEGIN wdFindGaut := wdDocGaut.Sections.Item(1).Headers.Item(1).Range.Find; // Search in Header //wdFindGaut.Execute(Field, Value0, Value1, Value0, Value0, Value0, Value1, Value1, Value0, Value, ReplaceAll); END; wdSelectionGaut.TypeText := 'This is an example'; //Show all markings wdView := wdAppGaut.ActiveWindow.View; wdView.ShowAll(TRUE); END; } CODE { BEGIN END. } }I hope someone can help to solve the problem. I think a simple command must be used, but which one?????? :-k
Thanks in advance.
0
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