+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 15 of 30

Macro to Batch/Mass Edit Headers/Footers on Multiple Word Documents (.docx) - Replace Text

  1. #1
    JamesFrames8
    Guest

    Question Macro to Batch/Mass Edit Headers/Footers on Multiple Word Documents (.docx) - Replace Text

    I need to edit the Headers on 37 documents and change the same phrase of text. I need a macro that finds a standard text phrase among the 37 word documents and replace it with a specific text phrase.

    I located a decent Macro that will edit the Body of the text but it won't change the header or footers (link below)

    http://www.extendoffice.com/document...ple-files.html

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,126

    Re: Macro to Batch/Mass Edit Headers/Footers on Multiple Word Documents (.docx) - Replace

    Try:
    Please Login or Register  to view this content.
    Note: the macro has its own folder browser and processes all files in the selected folder. As coded, it processes every possible range in a document, but the comments indicate what can be deleted to restrict processing to, say, just the headers.
    Cheers,
    Paul Edstein
    [MS MVP - Word]

  3. #3
    JamesFrames8
    Guest

    Re: Macro to Batch/Mass Edit Headers/Footers on Multiple Word Documents (.docx) - Replace

    Which points in the Macro do I need to add my inputs - which section do I put what I want to find and which section do I put what I need to replace?

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,126

    Re: Macro to Batch/Mass Edit Headers/Footers on Multiple Word Documents (.docx) - Replace

    The inputs are in the line:
    Fnd = "Find Text": Rep = "Replace Text"
    Change what's between the double-quotes for whatever you require.

  5. #5
    Registered User
    Join Date
    07-24-2014
    Location
    NY
    MS-Off Ver
    2010
    Posts
    4

    Re: Macro to Batch/Mass Edit Headers/Footers on Multiple Word Documents (.docx) - Replace

    I'm getting a ByRef argument type mismatch error when I use this code. Thoughts?

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,126

    Re: Macro to Batch/Mass Edit Headers/Footers on Multiple Word Documents (.docx) - Replace

    How are you running the code and what code line, if any, is highlighted when the error occurs (after clicking 'debug' if you're given that option)?

  7. #7
    Registered User
    Join Date
    07-24-2014
    Location
    NY
    MS-Off Ver
    2010
    Posts
    4

    Re: Macro to Batch/Mass Edit Headers/Footers on Multiple Word Documents (.docx) - Replace

    Hi,

    The Rng in Call RngFndRep(Rng, Fnd, Rep) is highlighted. What do you mean by "how do you run the code"? This happens if I run it from the developer window, or if I run it via "compile" within the VBA windo

  8. #8
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,126

    Re: Macro to Batch/Mass Edit Headers/Footers on Multiple Word Documents (.docx) - Replace

    What do you mean by "how do you run the code"?
    As in, are you running this from within Word, or from some other application?

  9. #9
    Registered User
    Join Date
    07-24-2014
    Location
    NY
    MS-Off Ver
    2010
    Posts
    4

    Re: Macro to Batch/Mass Edit Headers/Footers on Multiple Word Documents (.docx) - Replace

    From within Word. Thanks!

  10. #10
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,126

    Re: Macro to Batch/Mass Edit Headers/Footers on Multiple Word Documents (.docx) - Replace

    It appears I missed a variable declaration for Rng, but I don't see why that would cause the error you're reporting.

    After:
    wdDoc As Document
    add:
    , Rng As Range

  11. #11
    Registered User
    Join Date
    07-24-2014
    Location
    NY
    MS-Off Ver
    2010
    Posts
    4

    Re: Macro to Batch/Mass Edit Headers/Footers on Multiple Word Documents (.docx) - Replace

    That did the trick, good eye. It works perfectly for me now. Thanks!

  12. #12
    Registered User
    Join Date
    05-12-2010
    Location
    Manchester, England
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Macro to Batch/Mass Edit Headers/Footers on Multiple Word Documents (.docx) - Replace

    As coded, it processes every possible range in a document, but the comments indicate what can be deleted to restrict processing to, say, just the headers.
    Not sure what to delete, to make this work on just headers. The macro runs but nothing changes in my document headers

  13. #13
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,126

    Re: Macro to Batch/Mass Edit Headers/Footers on Multiple Word Documents (.docx) - Replace

    I'd have thought it fairly obvious you'd delete everything between ''Process everything except headers & footers' and ''Process headers & footers'.

    As for why nothing changes, that really depends on what you're using on the line:
    Fnd = "Find Text": Rep = "Replace Text"

  14. #14
    Registered User
    Join Date
    05-12-2010
    Location
    Manchester, England
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Macro to Batch/Mass Edit Headers/Footers on Multiple Word Documents (.docx) - Replace

    Ah, obvious now you explian, thanks for that, not very good with macros.
    It was my error it didn't work, copied the text to replace from the header, but included a space by mistake.
    Works perfectly now, saved me hours of work, so thank you so much!

  15. #15
    Registered User
    Join Date
    03-24-2017
    Location
    Texas
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    3

    Re: Macro to Batch/Mass Edit Headers/Footers on Multiple Word Documents (.docx) - Replace

    So I've got the macro working, I'll select the folder with all the documents in it and I can watch in file explorer as it opens each file. However, it will perform the change on some of the files and not the rest. I move the updated files to another folder and run the macro again. Again, it will update some of the files it didn't the first round, but not all of them. I keep doing this until all the files have been updated.

    Can anyone tell me what's going on and how to get it to do all the files with one run of the macro?

    BTW, thanks for the code.

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1