[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Searching for section breaks that have got landscape orientation

Posted on 2007-08-06
6
Medium Priority
?
185 Views
Last Modified: 2010-08-05
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
0
Comment
Question by:AndreasHermle
  • 4
  • 2
6 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 19649613
Hi Andreas.
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.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 19649779
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.PageSetup.Orientation)
        strOrientation2 = GetOrientationWord(ActiveDocument.Sections(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
0
 

Author Comment

by:AndreasHermle
ID: 19654154
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?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 19654852
OK Andreas. This sets the selection to the break that begins a landscaped section.

Sub Findsections()
Dim rng As Range
Dim sec As Section

    Set rng = Selection.Range
    rng.End = ActiveDocument.Range.End
    Do While rng.Find.Execute("^b")
        Set sec = rng.Sections(1)
        If ActiveDocument.Sections(sec.Index + 1).PageSetup.Orientation = wdOrientLandscape Then
            Exit Do
        End If
    Loop
    If rng.Find.Found Then
        rng.Select
        MsgBox "Found on page no: " & Selection.Information(wdActiveEndPageNumber)
    Else
        MsgBox "Not found"
    End If
End Sub

PS. Who's Greg? ;)
0
 

Author Comment

by:AndreasHermle
ID: 19656064
Great working as desired. Thank you very much.
As for Greg,  I mixed you up with sb.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 19657633
No harm done. I was already mixed up, anyway. :>)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
Suggested Courses
Course of the Month19 days, 7 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question