#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
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 |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Replace or apply new header in multiple files | Carchee | Word VBA | 41 | 01-26-2024 07:27 AM |
Find & Replace in Header/Footer in 1000 files | amodiammmuneerk@glenmarkp | Word | 12 | 03-05-2018 03:31 AM |
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 |
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 |