Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find and Replace Section Breaks

Status
Not open for further replies.

trifest

Programmer
Sep 5, 2002
52
0
0
US
Basically, I tried the find and replace with the ^b for section breaks but can't replace any of them with anything. I want all the section breaks deleted in my document since there's about 225 pages of it. Anyone have any suggestions. Thanks for the help.
 
What do you want to replace them with??? Are you sure they are section breaks, not page breaks? I hope you are very careful with this, because all header/footer information is held in section breaks.

What vesion are you using? I had no problem replacing ^b, with ^p, changing all section breaks to page breaks. Or replacing them with nothing, or replacing them with tabs.

What, precisely, do you want to happen?

Gerry
 
I'm trying to just remove all the section breaks in the document specifically section break (next page) . i need to combine a lot of material and can't seem to get it to work in Word 2003. Any tips?
 
And you tried using find and replace? As stated, using Find and Replace, I had NO problems replacing section breaks with, tabs, with page breaks, with nothing. Word 2002 (XP)

I am writing some code, that may help.

Again, I really want to stress my question: are you sure this is what you need to do? Are there are any continuous sections breaks that you do NOT want to remove? Are there are Form ields in the document? Do you have any headers and footers that need to be preserved?

Gerry
 
trifest,

As Gerry correctly stated,
Gerry said:
I hope you are very careful with this, because all header/footer information is held in section breaks.

Then YOU stated, referring to Section Break - Next Page
trifest said:
i need to combine a lot of material and can't seem to get it to work in Word 2003.

What are you trying to get to work that does not seem to work with the section breaks?


Skip,

Want to get great answers to your Tek-Tips questions? Have a look at faq222-2244
 
Essentially what I'm trying to do is that I have sections that I want to combine since I wrote a mail merge function that grabs records from an Access Database but it then puts section breaks after each record but I don't want section breaks after each record but to have them all combined.

I don't have any headers or footers so I'm not concerned about that at all. hope this clears it up.
 
Then replace section breaks ^b with nothing.

:)

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at faq222-2244
 
Thanks Skip, for re-enforcing the question, because truly, it is not clear, precisely what you want to do. And I am not sure if you truly have SECTION breaks, as opposed to PAGE breaks. Here is some code that may help. It runs through all the sections, and detects what type they are. You could modify each Case to do a specific action, depending on the type of section break.
You state that you specifically want to remove Section Break (Next Page). You could do that with this, by putting code in the Case that detexts a Next Page type section breaks.

NOTE! It goes to the first section, first. The first section is ALWAYS Type = 2 (Next Page). That is, a blank document, with nothing in it, actually contains a section break, and it is a Next Page type. That is because section breaks DO contain all header/footer information - and even a blank document has a header/footer.

Code:
Sub ListSectionBreaks()
Dim var
Dim i As Integer
i = 1

' go to first section
Selection.GoTo What:=wdGoToSection, Which:=wdGoToFirst, Count:=1, Name:=""

For var = 1 To ActiveDocument.Sections.Count
Select Case ActiveDocument.Sections.Item(i).PageSetup.SectionStart
    Case 0
        MsgBox "Total number of sections in document = " & _
        ActiveDocument.Sections.Count & vbCrLf & _
        "This is Section " & i & ".  The Type = " & _
        ActiveDocument.Sections.Item(i).PageSetup.SectionStart _
        & " (Continuous )."
    Case 1
        MsgBox "Total number of sections in document = " & _
        ActiveDocument.Sections.Count & vbCrLf & _
        "This is Section " & i & ".  The Type = " & _
        ActiveDocument.Sections.Item(i).PageSetup.SectionStart _
        & " (Column Break)."
    Case 2
        MsgBox "Total number of sections in document = " & _
        ActiveDocument.Sections.Count & vbCrLf & _
        "This is Section " & i & ".  The Type = " & _
        ActiveDocument.Sections.Item(i).PageSetup.SectionStart _
        & " (NextPage)."
    Case 3
        MsgBox "Total number of sections in document = " & _
        ActiveDocument.Sections.Count & vbCrLf & _
        "This is Section " & i & ".  The Type = " & _
        ActiveDocument.Sections.Item(i).PageSetup.SectionStart _
        & " (Even Page)."

    Case 4
        MsgBox "Total number of sections in document = " & _
        ActiveDocument.Sections.Count & vbCrLf & _
        "This is Section " & i & ".  The Type = " & _
        ActiveDocument.Sections.Item(i).PageSetup.SectionStart _
        & " (Odd Page)."
    Case Else
        MsgBox "something else"
End Select
    Selection.GoTo What:=wdGoToSection, Which:=wdGoToNext, Count:=1, Name:=""
    i = i + 1
Next
End Sub

However, again, I do not see why you can not do a find and replace, because it works. Find = ^b; Replace = whatever you like.

I suggest you make a copy of your document, and save it. If you are going to try and remove ALL your section breaks, and you have header/footers, or something else that depends on them...well...

Gerry
 
It's strange. I've been trying to do the find and replace and I tried it on Word 2000, XP, and 2003. and none of them can replace ^b. It can find the breaks but does not replace them. I have seen microsoft articles that state ^b is find function only. Thanks for the code and I will give it a try.
 
I find this hard to believe. I have tested everything and Find/Replace works with ^b. OK then.

Code:
Sub DeleteALLSections()
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^b"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub

Try running this directly, by code. This is simply Find and Replace. DO NOT RUN THIS, until you have made a copy of your file! I still am not sure you are doing the right thing...but hey, you say find and replace does not work? Run this on a copy and let me know if it works. If not, then I gotta know, because, well it should.

Gerry
 
Strange thing is the code will only do it for the very last section break. and not the other 224 sections breaks within the doc. but if i do a find on ^b it goes through all of them. Am I doing something wrong here? Thanks for the code.
 
Is there any ANY KIND OF FORMATTING defined in the search and replace dialog box? If so, delete it, and then run your "section break search and replace".
searchreplace.jpg

If there is any formatting associated, it would be in the first two red-circled areas. To clear ALL associated formatting from the search and replace dialog box, place the cursor in the SEARCH window and click the "No Formatting" button then place the cursor in the REPLACE window and click the "No Formatting" button again.
 
there was no formatting enabled on the find and replace. is there another option somewhere that i should be aware of?
 
No, I was just hoping that was the problem. Sorry! Sure would like to get a resolution for you.
 
Something pretty odd there, because, I can do a find a replace of section breaks with no problems. Anyway, let me know if the delete all section break code works. If it doesn't....hmmmm, I think I will leave it to dcompto, for whom, no search is unrewarded.... [2thumbsup]

Gerry
 
Unfortunately, the code didn't work. it just replaced the very last section break. can't understand why i'm having so many problems with this.
 
Essentially what I'm trying to do is that I have sections that I want to combine since I wrote a mail merge function that grabs records from an Access Database but it then puts section breaks after each record but I don't want section breaks after each record but to have them all combined.
If acceptable to you, you can change your merge document type to Catalog and re-merge and it will not place section breaks between the records.

Open your Main Document
Click the Mail Merge Helper button
Click Create
Choose Catalog
Click Change Document Type
Save and re-merge
 
dcompto,

that worked perfectly, you were right. i was merging as a letter. doh! wish i had thought of that. i used the directory format in word 2003 and it worked perfectly. thanks for the help guys. you saved me a ton of time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top