Andreas Hermle
asked on
Searching for section breaks that have got landscape orientation
Dear Experts:
Is it possible to search for only those section breaks that have got LANDSCAPE orientation, using VBA?
Help is appreciated. Thank you very much in advance.
Regards, Andreas
Is it possible to search for only those section breaks that have got LANDSCAPE orientation, using VBA?
Help is appreciated. Thank you very much in advance.
Regards, Andreas
Did my usual thing of forgetting to post the code:
Option Explicit
Sub Findsections()
Dim rng As Range
Dim sec As Section
Dim strOrientation1 As String
Dim strOrientation2 As String
Set rng = ActiveDocument.Content
Do While rng.Find.Execute("^b")
Set sec = rng.Sections(1)
strOrientation1 = GetOrientationWord(sec.Pag eSetup.Ori entation)
strOrientation2 = GetOrientationWord(ActiveD ocument.Se ctions(sec .Index + 1).PageSetup.Orientation)
MsgBox "Section break at " & rng.Start & vbCrLf & _
"ends a " & strOrientation1 & " section and begins a " & strOrientation2 & " section"
Loop
End Sub
Function GetOrientationWord(o As Integer) As String
Select Case o
Case wdOrientLandscape
GetOrientationWord = "Landscape"
Case wdOrientPortrait
GetOrientationWord = "Portrait"
End Select
End Function
Option Explicit
Sub Findsections()
Dim rng As Range
Dim sec As Section
Dim strOrientation1 As String
Dim strOrientation2 As String
Set rng = ActiveDocument.Content
Do While rng.Find.Execute("^b")
Set sec = rng.Sections(1)
strOrientation1 = GetOrientationWord(sec.Pag
strOrientation2 = GetOrientationWord(ActiveD
MsgBox "Section break at " & rng.Start & vbCrLf & _
"ends a " & strOrientation1 & " section and begins a " & strOrientation2 & " section"
Loop
End Sub
Function GetOrientationWord(o As Integer) As String
Select Case o
Case wdOrientLandscape
GetOrientationWord = "Landscape"
Case wdOrientPortrait
GetOrientationWord = "Portrait"
End Select
End Function
ASKER
Greg, Looks very sophisticated as always and it seems to work although I am not quite sure what the message box says:
It says section break at 13676 and section break at a 136657. What do these figures stand for?
Actually I wanted the macro to jump to the nearest section break that has landscape orientation whenever I run the macro?
It says section break at 13676 and section break at a 136657. What do these figures stand for?
Actually I wanted the macro to jump to the nearest section break that has landscape orientation whenever I run the macro?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great working as desired. Thank you very much.
As for Greg, I mixed you up with sb.
As for Greg, I mixed you up with sb.
No harm done. I was already mixed up, anyway. :>)
A thunderstorm just gave us a power cut, so I've had to retype everthing. It was heading your way. You might see it tomorrow, so watch out for it.
As you know, there is only one search symbol for a section break, and we have to examine the sections on either side of the break to find if it's a 'Landscape' break or not.
Actually, it's not clear whether you need the break at the beginning or the one at the end of the section. It is the one at the end that carries the page setup information such as orientation. Try deleting one, and you will see that the new combined section has the formatting of the second.