Ben Gribaudo
Ben Gribaudo

Reputation: 5147

Inserting a Page After Drawing a Shape

Using VBA, I can draw a circle and then insert a new page. However, the new page is inserted before the page with the circle on it (or the correct way to look at it might be: inserting the new page bumps the circle to the new page). How to I insert a new page so that it comes after the page with the circle on it?

Code demonstrating the problem:

Sub InsertShape()
  ActiveDocument.Shapes.AddShape(msoShapeOval, 154.8, 94.2, 189#, 129# _
      ).Select

  Selection.Collapse
  Selection.InsertBreak Type:=wdPageBreak
End Sub

(In the simplistic example above, inserting the page break before drawing the circle achieves my goal. However, when the decision of whether to insert the new page needs to conditionally occur at some point after the circle has been drawn, moving insert page before drawing the circle isn't an acceptable solution.)

Thank you!

Upvotes: 0

Views: 467

Answers (1)

Tim Williams
Tim Williams

Reputation: 166196

Collapse takes an argument which specifies which direction the collapse should occur.

By default, if no argument is given, it collapses to the start of the selection/range, so try providing the specific direction you want:

Selection.Collapse Direction:=wdCollapseEnd

See: http://msdn.microsoft.com/en-us/library/office/aa171856(v=office.11).aspx

Upvotes: 1

Related Questions