Determine which page where a shape is placed




Currently i have a code which will print OMR Mark on each pages. Basically i
insert a canvas into each page and subsequently an OMR Mark Line Series are
inserted into the canvas.

Recently i found an issue that somehow one of the canvas is placed out of a
page and it appears at the previous page instead of the current page.

Below is the code snippet in how i inserted canvas as well as OMR Marks into
each page:

' Start Code Snippet
Sub GenerateOMR()
Dim ShpCanvas As Shape
Dim MaxPages As Integer
Dim PNo As Integer
MaxPages = Selection.Information(wdNumberOfPagesInDocument)
For PNo = 1 To MaxPages
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst, Count:=PNo,

Select Case PNo
Case 1
Set ShpCanvas = ActiveDocument.Shapes.AddCanvas(0, 0.5, 600,
Case Else
Set ShpCanvas = ActiveDocument.Shapes.AddCanvas(0, 0, 600,

End Select

' Add a canvas on each page
With ShpCanvas
.Name = "OMR_Canvas_" & CStr(PNo)
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
End With

' Insert a white background rectange and remove the rectangle border
With ShpCanvas.CanvasItems.AddShape(msoShapeRectangle, 536, 0, 64,
.Name = "OMR_WhiteBackground_" & CStr(PNo)
.Fill.ForeColor.RGB = RGB(255, 255, 255)
.Line.ForeColor.RGB = RGB(255, 255, 255)
End With

PrintOMRPage ShpCanvas, PNo
Next PNo
End Sub
' End Code Snippet

There is a custom method called PrintOMRPage method which is not relevant

My question now, how do i know whether a canvas has been inserted into a
page ? Basically i will loop in all the pages and check whether a canvas has
been inserted into that page. Apparently i cannot find the correct way.

I have tried to check using ActiveDocument.Shapes(1).Top and validate
whether the Top position is a negative value. But apparently the Top position
is always measured from the top of each page.

Thanks for the help.

hadi teo


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