Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 07-07-2022, 06:52 AM
ladracer ladracer is offline Bulk Removal of Paragraph Mark in Header Windows 10 Bulk Removal of Paragraph Mark in Header Office 2010
Novice
Bulk Removal of Paragraph Mark in Header
 
Join Date: Mar 2021
Posts: 18
ladracer is on a distinguished road
Default Bulk Removal of Paragraph Mark in Header

I have a folder containing more than 500 documents, each with a header that has some text followed by 3 paragraph marks. I am looking to reduce that to only the text followed by 2 paragraph marks. Thought it would be fairly simple, but it has proved difficult for me. I have tried Chr(13) and ^p without success. Tried a bevy of different iterations. Please help.

Sub ReplaceHeaderTextInFolder2()
'
Dim objDoc As Document
Dim strFile As String
Dim strFolder As String
Dim strFindText As String
Dim strReplaceText As String
Dim xSelection As Selection
Dim xSec As Section
Dim xHeader As HeaderFooter

' Pop up input boxes for user to enter folder path, the finding and replacing texts.
strFolder = InputBox("Enter folder path here:")
strFile = Dir(strFolder & "" & "*.docx", vbNormal)
strFindText = "^p^p^p"
strReplaceText = "^p^p"

' Open each file in the folder to search and replace texts. Save and close the file after the action.
While strFile <> ""
Set objDoc = Documents.Open(FileName:=strFolder & "" & strFile)
With objDoc
For Each xSec In objDoc.Sections


For Each xHeader In xSec.Headers
xHeader.Range.Select
Set xSelection = objDoc.Application.Selection
With xSelection
.HomeKey Unit:=wdStory


With xSelection.Find
'.Text = strFindText
'.Replacement.Text = strReplaceText

.Text = strFindText
.Replacement.Text = strReplaceText

.Forward = True
.Wrap = wdFindContinue
'.Wrap = wdFindStop
.Format = False
.MatchCase = False


.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False


End With
xSelection.Find.Execute Replace:=wdReplaceAll
End With
Next xHeader
Next xSec
objDoc.Save
objDoc.Close
strFile = Dir()
End With
Wend

End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
a macro to replace paragraph mark with a space applies effect on paragraph marks after the selection drrr Word VBA 2 08-24-2021 03:05 AM
Bulk Removal of Paragraph Mark in Header What is this paragraph mark called booneyrex Word 8 03-04-2021 04:15 AM
Bulk Removal of Paragraph Mark in Header Indention below paragraph mark... kikola Word VBA 13 05-26-2020 06:21 AM
Bulk Removal of Paragraph Mark in Header Please help with header and footer removal pwangdel Word 3 11-03-2011 06:10 AM
Bulk Removal of Paragraph Mark in Header Final paragraph mark Caroline Word 2 02-22-2011 10:39 AM

Other Forums: Access Forums

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


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