Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2007

Tip: Looking for answers? Try searching our database.

Continuous section break

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
LEU - 28 Apr 2007 19:40 GMT
I have documents that I am trying to clean up. They have numerous Section
Break(Next page) and Section Break(Continuous) in them. I am trying to write
a macro to just replace the Section Break(Continuous) with a hard return.
What I have written below replaces all the Section Breaks. How do I replace
only the Section Break(Continuous)?

Dim SearchRange As Range
Set SearchRange = ActiveDocument.Range
With SearchRange.Find
   .ClearFormatting
   .Replacement.ClearFormatting
   .Text = "^b"
   .Replacement.Text = "^p"
   .Execute Replace:=wdReplaceAll
End With
Helmut Weber - 28 Apr 2007 19:45 GMT
Hi LEU,

see: http://tinyurl.com/36oyc6

try the function "KindofBreak12"

HTH

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

LEU - 29 Apr 2007 04:12 GMT
Hi Helmut,

I'm not sure what you mean when you said to try "KinfofBreak12". I looked at
the site but I didn't understand it. Could you give me more detail on how to
write this?

Thanks
LEU

> Hi LEU,
>
[quoted text clipped - 3 lines]
>
> HTH
Helmut Weber - 29 Apr 2007 09:39 GMT
Hi LEU,

>I'm not sure what you mean when you said to try "KinfofBreak12". I looked at
>the site but I didn't understand it. Could you give me more detail on how to
>write this?

You search for chr(12).
If found, you feed the found range of this chr(12)
into the function kindofbreak12.

The function returns a long number,
which represents the kind of pagebreak,
as the pagebreak character itself
can't tell you what kind of pagebreak it stands for.
What kind of pagebreak it is, is defined
in the section's pagesetup sectionstart.

In addition, if the found character 12
and the next character are in the same section,
then we got an ordinary pagebreak.

You may start with something like the code below.

Couldn't get it to work with range,
no matter how hard I tried,
maybe somebody else is smarter than me today.

This somebody should think of any number
of continuous pagebreaks and other pagebreaks
not separated by any other character.
Here and now it is over my head.

HTH nevertheless:

Public Function KindofBreak12(ByVal rtmp As Range) As Long
Dim lSct1 As Long  ' counter for sections
Dim lSct2 As Long  ' counter for sections
rtmp.start = ActiveDocument.Range.start
lSct1 = rtmp.Sections.Count ' count sections
rtmp.End = rtmp.End + 1     ' extend range
lSct2 = rtmp.Sections.Count ' count sections again
If lSct1 = lSct2 Then       ' next caracter is in the same section
  KindofBreak12 = -1       ' ordinary pagebreak
Else
  KindofBreak12 = _
ActiveDocument.Sections(lSct2).PageSetup.SectionStart
End If

'wdSectionContinuous ' 0
'wdSectionNewPage ' 2
'wdSectionEvenPage ' 3
'wdSectionOddPage '4

End Function

Sub Test90012A()
ActiveDocument.Range(0, 0).Select
With Selection.Find
  .Text = "^0012"
  While .Execute
     If KindofBreak12(Selection.Range) = 0 Then
        Selection.Text = Chr(13)
        Selection.End = ActiveDocument.Range.End
     End If
   Wend
End With
End Sub

Don't forget to reset search options beforehand, like

Public Sub ResetSearch()
With Selection.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Text = ""
  .Replacement.Text = ""
  .Forward = True
  .Wrap = wdFindContinue
  .Format = False
  .MatchCase = False
  .MatchWholeWord = False
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = False
  .Execute
End With
End Sub

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

LEU - 29 Apr 2007 18:56 GMT
Hi Helmut

I copied tried your macro and and ran it. It goes through the document and
finds all of the Section Breaks but it does not replace the Section
Break(Continuous) with a hard return. I must be missing something.

LEU

> Hi LEU,
>
[quoted text clipped - 83 lines]
> End With
> End Sub
Helmut Weber - 29 Apr 2007 21:38 GMT
Hi LEU,

this is a nightmare.

My macro finds all instances of section break (continuous),
and replaces them with a paragraph mark, IMHO.

However, if a section break (continuous) is preceded
by e.g. a section break (even page), this break turns
into a new section break (continuous).
So, one would have to remember the kind of section pagesetup
of the actual section and restore it after replacing
the section break (continuous).

Sub Test90012A()
Dim lTemp As Long
Dim xTemp As Range
Set xTemp = ActiveDocument.Range
ActiveDocument.Range(0, 0).Select
With Selection.Find
  .Text = "^0012"
  While .Execute
     If KindofBreak12(Selection.Range) = 0 Then
        xTemp.End = Selection.Range.End
        lTemp = xTemp.Sections.Last.PageSetup.SectionStart
        Selection.Text = Chr(13)
        xTemp.Sections.Last.PageSetup.SectionStart = lTemp
        Selection.End = ActiveDocument.Range.End
     End If
   Wend
End With
End Sub

Seemed to be a simple question at first.
But as it happens, the complications are endless.

Once again, all co-readers are invited.

This is driving me up the wall...

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

LEU - 29 Apr 2007 23:30 GMT
Helmut,

THIS TIME IT WORKED!!!!!!!  Thank you so much for all your help.

LEU

> Hi LEU,
>
[quoted text clipped - 35 lines]
>
> This is driving me up the wall...

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.