Get the Type of Break programatically

J

Jon.NET

Hi there,

Is there anyway to get the Type of Break in a Word Document programmatically?

Getting the Break Range in a Section and getting the Text property, returns
"\f" as a string, for both a Section and Page Breaks.

Any Ideas?

Thanks in Advance

Jon
 
C

Cindy M.

Hi =?Utf-8?B?Sm9uLk5FVA==?=,
Is there anyway to get the Type of Break in a Word Document programmatically?

Getting the Break Range in a Section and getting the Text property, returns
"\f" as a string, for both a Section and Page Breaks.
For determining the type of section break of the current section you can use
Selection.Sections(1).PageSetup.SectionStart

For determing whether a break is a section or page break I think you'd need to
query the section index number of a point preceding and following the ANSI 12
character (\f) to see whether or not they match

Selection.Sections.Item(1).Index

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
H

Helmut Weber

Hi Jon,

Sub test012()
Dim rDcm As Range ' the documents range
Set rDcm = ActiveDocument.Range
Selection.StartOf Unit:=wdStory, Extend:=wdMove
With Selection.Find
.Text = Chr(12)
While .Execute
MsgBox KindofBreak12(Selection.Range)
Wend
End With
'wdSectionContinuous ' 0
'wdSectionNewPage ' 2
'wdSectionEvenPage ' 3
'wdSectionOddPage '4

End Sub

Public Function KindofBreak12(ByVal rTmp As Range) As String
Dim lSct1 As Long ' counter for sections
Dim lSct2 As Long ' counter for sections
Dim lKoSc As Long ' kind of section.pagesetup.sectionstart
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 = "ordinary page break"
Exit Function
End If
' next character is in the next section
lKoSc = ActiveDocument.Sections(lSct2).PageSetup.SectionStart
Select Case lKoSc
Case 0: KindofBreak12 = "wdSectionContinuous"
Case 2: KindofBreak12 = "wdSectionNewPage"
Case 3: KindofBreak12 = "wdSectionEvenPage"
Case 4: KindofBreak12 = "wdSectionOddPage"
End Select

End Function

Which for certain cases would need some more elaboration.


--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top