Searching for section breaks that have got landscape orientation

A

andreas

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
 
J

Jonathan West

andreas said:
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

Dim oSection as Section
For Each oSection in ActiveDocument.Sections
If oSection.PageSetup.Orientation = wdOrientationLandscape Then
'it is a landscape section
Else
'it isn't
End If
Next oSection
 
H

Helmut Weber

Hi Andreas,
Is it possible to search for only those section breaks that have got
LANDSCAPE orientation, using VBA?

hmm..., I think you want to find out
what section breaks cause landscape orientation
in the following section!

The section break, which causes this,
may be in an portrait section however.

You could expand Jonathan's solution
to locate the section break preceeding
the landscape section.

Or you could try this one:

Sub Test555()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = Chr(12)
While .Execute
MsgBox rDcm.Characters.Last.Next.PageSetup.Orientation
' 1 = landscape
Wend
End With
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

andreas

Dim oSection as Section
For Each oSection in ActiveDocument.Sections
If oSection.PageSetup.Orientation = wdOrientationLandscape Then
'it is a landscape section
Else
'it isn't
End If
Next oSection

Jonathan,

thank you, it is working
Regards, Andreas
 
A

andreas

Hi Andreas,


hmm..., I think you want to find out
what section breaks cause landscape orientation
in the following section!

The section break, which causes this,
may be in an portrait section however.

You could expand Jonathan's solution
to locate the section break preceeding
the landscape section.

Or you could try this one:

Sub Test555()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
.Text = Chr(12)
While .Execute
MsgBox rDcm.Characters.Last.Next.PageSetup.Orientation
' 1 = landscape
Wend
End With
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Helmut,

it is half working: the section break that features the landscape
orientation is found, but the macro loops 12 times in a document with
three sections.

Regards, Andreas
 

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