Hi,
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
ClearOMR
MaxPages = Selection.Information(wdNumberOfPagesInDocument)
For PNo = 1 To MaxPages
Selection.GoTo What:=wdGoToPage, Which:=wdGoToFirst, Count:=PNo, Name:=""
Select Case PNo
Case 1
Set ShpCanvas = ActiveDocument.Shapes.AddCanvas(0, 0.5, 600, 300)
Case Else
Set ShpCanvas = ActiveDocument.Shapes.AddCanvas(0, 0, 600, 300)
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 line
With ShpCanvas.CanvasItems.AddShape(msoShapeRectangle, 536, 0, 64, 300)
.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 here.
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