E
Esther
I have a large document with an table of contents, some general pages
and after that the core of the document: text, each chapter in a
section, with headers etc. The margins of the odd and even pages are
different. Also different on even and odd pages is an textbox. Some
paragraphs have an extra textbox, on even pages at the left side and on
odd pages on the right side. When I add text, and a paragraph with an
explaining textbox moves to a different page, the textbox is on the
wrong side of the page. I want to write a macro that loops all
textboxes and eventually moves them. I started by writing code that
loops all textboxes.
Dim mijnVak As Rectangle
Dim mijnPagina As Page
Dim i As Integer
For i = 1 To ActiveDocument.ActiveWindow.Panes(1).Pages.Count
Set mijnPagina = ActiveDocument.ActiveWindow.Panes(1).Pages(i)
For Each mijnVak In mijnPagina.Rectangles
If mijnVak.RectangleType = wdShapeRectangle Then
mijnVak.Range.Select
If mijnVak.Range.ShapeRange.Type = msoTextBox Then
MsgBox mijnVak.Range.ShapeRange.TextFrame.TextRange
'this should be the code to move the textbox
End If
End If
Next
Next
When running this code, the number of pages is determined to be 50,
which is correct. But when selecting pagenumber 6, VBA says that this
item does not exist in the collection. I previously tried it with a
for-each-loop, with the same result.
What's wrong or what am I missing?
Thanx! Esther
and after that the core of the document: text, each chapter in a
section, with headers etc. The margins of the odd and even pages are
different. Also different on even and odd pages is an textbox. Some
paragraphs have an extra textbox, on even pages at the left side and on
odd pages on the right side. When I add text, and a paragraph with an
explaining textbox moves to a different page, the textbox is on the
wrong side of the page. I want to write a macro that loops all
textboxes and eventually moves them. I started by writing code that
loops all textboxes.
Dim mijnVak As Rectangle
Dim mijnPagina As Page
Dim i As Integer
For i = 1 To ActiveDocument.ActiveWindow.Panes(1).Pages.Count
Set mijnPagina = ActiveDocument.ActiveWindow.Panes(1).Pages(i)
For Each mijnVak In mijnPagina.Rectangles
If mijnVak.RectangleType = wdShapeRectangle Then
mijnVak.Range.Select
If mijnVak.Range.ShapeRange.Type = msoTextBox Then
MsgBox mijnVak.Range.ShapeRange.TextFrame.TextRange
'this should be the code to move the textbox
End If
End If
Next
Next
When running this code, the number of pages is determined to be 50,
which is correct. But when selecting pagenumber 6, VBA says that this
item does not exist in the collection. I previously tried it with a
for-each-loop, with the same result.
What's wrong or what am I missing?
Thanx! Esther