Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-25-2018, 04:02 AM
LG1972 LG1972 is offline Find and replace header text across multiple files Windows 7 64bit Find and replace header text across multiple files Office 2010
Novice
Find and replace header text across multiple files
 
Join Date: Dec 2018
Posts: 1
LG1972 is on a distinguished road
Default Find and replace header text across multiple files

I'm looking for a macro that will allow me to find and replace header text across multiple files. I've tried editing macros I found for doing just that in word but with no luck. Can someone help me edit this macro so it will work with excel documents?

This is the word macro I have used:





Code:
Sub ReplaceTextInHeaderInMultiDoc()
  Dim StrFolder As String
  Dim strFile As String
  Dim objDoc As Document
  Dim dlgFile As FileDialog
  Dim strFindText As String
  Dim strReplaceText As String
 
  Set dlgFile = Application.FileDialog(msoFileDialogFolderPicker)
 
  With dlgFile
    If .Show = -1 Then
      StrFolder = .SelectedItems(1) & "\"
    Else
      MsgBox "Please select the target folder."
      Exit Sub
    End If
  End With
 
  strFindText = InputBox("Enter text to be found:", "Find Text")
  strReplaceText = InputBox("Enter new text:", "Replace Text")
 
  strFile = Dir(StrFolder & "*.docx", vbNormal)
 
  While strFile <> ""
    Set objDoc = Documents.Open(FileName:=StrFolder & strFile)
    For nPageNum = 1 To Selection.Information(wdNumberOfPagesInDocument)
      Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=nPageNum
      Application.Browser.Target = wdBrowsePage
      objDoc.Bookmarks("\page").Range.Select
      With objDoc.ActiveWindow
        .ActivePane.View.SeekView = wdSeekCurrentPageHeader
        With .Selection.Find
          .ClearFormatting
          .Text = strFindText
          .Replacement.ClearFormatting
          .Replacement.Text = strReplaceText
          .Wrap = wdFindContinue
          .Execute Replace:=wdReplaceAll
        End With
      End With
    Next nPageNum
    objDoc.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    objDoc.Save
    objDoc.Close
    strFile = Dir()
  Wend
End Sub
Reply With Quote
  #2  
Old 12-25-2018, 04:27 AM
Pecoflyer's Avatar
Pecoflyer Pecoflyer is offline Find and replace header text across multiple files Windows 7 64bit Find and replace header text across multiple files Office 2010 64bit
Expert
 
Join Date: Nov 2011
Location: Brussels Belgium
Posts: 2,767
Pecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant future
Default

Hi and welcome
please wrap code with code tags.
To do this edit your post - select the code and click the #button.
Thank you
__________________
Did you know you can thank someone who helped you? Click on the tiny scale in the right upper hand corner of your helper's post
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and replace header text across multiple files Replace or apply new header in multiple files Carchee Word VBA 41 01-26-2024 07:27 AM
Find and replace header text across multiple files Find & Replace in Header/Footer in 1000 files amodiammmuneerk@glenmarkp Word 12 03-05-2018 03:31 AM
Find and replace header text across multiple files Find & Replace text in Field Code across multiple documents RPM7 Word VBA 6 05-12-2017 12:58 AM
Need to find/replace text in many word files - but text is in embedded word files semple.13 Word VBA 5 11-03-2015 01:20 PM
Find and replace header text across multiple files Created VBA to Find and Replace in Body, Header and Footer with Highlighting the replacement text QA_Compliance_Advisor Word VBA 11 09-23-2014 04:40 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:08 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft