Word Automation with searching in Word Header?

elwin68elwin68 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.
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.
Sign In or Register to comment.