View Single Post
 
Old 06-29-2018, 01:32 PM
kkkwj kkkwj is offline Windows 10 Office 2016
Novice
 
Join Date: Nov 2017
Posts: 6
kkkwj is on a distinguished road
Default what are the rules for how to anchor a shape?

I'm trying to generate a series of pages in Word and add some shapes to each page. The code below works, but I don't understand why (or how) the shape-anchoring works.

The shapes get anchored to the new paragraph that I insert. If I don't insert that paragraph, all three sets of shapes end up stacked on each other on the last page in the series. Why don't the shapes anchor themselves to the paragraphs that I create when I insert the "New page" text? Why is a second new paragraph required? Thank you.

Code:
    npages = 3
    For i = 1 To 3
      If (i <= npages) Then
         Selection.Text = "New Page " + i
         Selection.Collapse wdDirection:=wdCollapseEnd
         
         ' the shapes get anchored to this paragraph below, not to the text above. Why?
         ' If I take out the paragraph, all 3 sets of shapes stack on each other,
         ' on the very last page of the set. Why?
         Selection.InsertParagraph
         'set shape = doc.shapes.addshape(rectangle,left,top,wdith,height)
         
         ' don't generate a new page after the last page of the series
         If (i < npages) Then
            Selection.InsertBreak Type:=wdPageBreak
         End If
      End If
    Next
Reply With Quote