web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Find/Replace in MS Word (header, footer)

(0) ShareShare
ReportReport
Posted on by 20

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)
  • Scott Wright Profile Picture
    on at

    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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans