'Print Grid for any page
Sub priPrintGrid()
Dim lintPageNum As Integer
Dim lintGridWidth As Integer
Dim lintScaleLeft As Integer
Dim lintScaleWidth As Integer
Dim llngRows As Long
Dim llngCols As Long
Dim lstrText As String
Dim lintLeftPosn As Integer
Dim lintColWidth As Integer
Dim lintColAlign As Integer
Dim lintTextWidth As Integer
Dim lintPrintSpace As Integer
On Error Resume Next
lintPageNum = 1
lintGridWidth = Grid1.Width
lintScaleLeft = Printer.ScaleLeft
lintScaleWidth = Printer.ScaleWidth
'Print Grid rows
With Grid1
For llngRows = 0 To .Rows -1
For llngCols = 0 To .Cols - 1
lstrText = Trim$(.TextMatrix(llngRows, llngCols))
lintTextWidth = Printer.TextWidth(lstrText)
lintLeftPosn = .ColPos(llngCols) / lintGridWidth * lintScaleWidth
lintColWidth = .ColWidth(llngCols) / lintGridWidth * lintScaleWidth
lintColAlign = .ColAlignment(llngCols)
'Print cell
priPrintCell lstrText, lintTextWidth, lintLeftPosn, lintColWidth, lintColAlign
Next
Printer.Print " "
'Test for new page
With Printer
lintPrintSpace = .ScaleHeight - .ScaleTop - .CurrentY
End With
If lintPrintSpace < 3 * Printer.TextHeight("A") Then
lintPageNum = lintPageNum + 1
If lintPageNum \ 5 = lintPageNum / 5 Then Printer.EndDoc
End If
Next
End With
End Sub
'Print grid cells
Sub priPrintCell(lstrText As String, lintTextWidth As Integer, _
lintLeftPosn As Integer, lintColWidth As Integer, _
lintColAlign As Integer)
Dim lintMaxText As Integer
On Error Resume Next
If lintColAlign = flexAlignLeftCenter Then 'Grid / total
Printer.CurrentX = lintLeftPosn + 80 'Left align
Else
Printer.CurrentX = lintLeftPosn + (lintColWidth - lintTextWidth) 'Right align
End If
'In case text is wider than column
If lintColWidth > 0 And lintColWidth < lintTextWidth Then 'Reduce column width
lintMaxText = Round(lintColWidth / lintTextWidth * Len(lstrText), 0) - 1
lstrText = Left$(lstrText, lintMaxText)
End If
If lintColWidth > 0 Then Printer.Print lstrText;
End Sub