
I would like to replace string in the MS Word file and following MS NAV code is working fine:
ltxt_ReplaceBy := 'BB';
ltxt_ToSearch := 'AA';
lint_Type1 := 1;
lint_Type2 := 1;
lint_Type3 := 1;
ltxt_Type1 := '';
laut_wrdApp.Selection.GoTo(lint_Type1,lint_Type2,lint_Type3,ltxt_Type1);
laut_wrdApp.Selection.Find.ClearFormatting;
laut_wrdApp.Selection.Find.Replacement.ClearFormatting;
lint_Type1 := 1;
lint_Type2 := 2;
laut_wrdApp.Selection.Find.Execute(ltxt_ToSearch,lbln_False,lbln_False,lbln_False,lbln_False,
lbln_False,lbln_True,lint_Type1,lbln_False,ltxt_ReplaceBy,lint_Type2,lbln_False,lbln_False,lbln_False,lbln_False);
The problem is that the replacement does not happen i Header and Footer.
I tried a tons of options and nothing worked for me. Can anybody help me please?
Regards
*This post is locked for comments
I have the same question (0)Hello ttss82,
I understand that you are having issues with using NAV Automation controls to find and replace test strings in the Header and Footer of word documents. You have code that works find for what would be the body of a Word doc, but doesn't replace anything in the Header or Footer. From what I'm researched, the Header and Footer will be different Sections, and need to be designated (selected). For example:
WrdDoc.Sections.Footers.Range.Select
Once selected you would execute your Find.
wrdApp.Selection.Find.Execute(...)
I haven't tested this to verify that it will work in NAV and it would take me a bit to familiarize myself with the Word Object Model to setup a test, but I have included documentation.Section Interface
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.section.aspx
How to: Add Headers and Footers to Documents
http://msdn.microsoft.com/en-us/library/ms178795(VS.80).aspx
HeaderFooter Members
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.headerfooter_members.aspx
Word Object Model Overview
http://msdn.microsoft.com/en-us/library/kw65a0we(VS.80).aspx
Plan:
I hope the above information is helpful. If you still have issues I could try testing this and see what I can determine.
Best regards, Scott Wright | Senior Technical Support Engineer | Microsoft Dynamics NAV