http://www.vb-helper.com/howto_listview_print.html Private Sub mnuFilePrint_Click() Printer.CurrentX = 1440 Printer.CurrentY = 1440 PrintListView ListView1 Printer.EndDoc End SubPrivate Sub PrintListView(lvw As ListView) Const MARGIN = 60 Const COL_MARGIN = 240Dim ymin As Single Dim ymax As Single Dim xmin As Single Dim xmax As Single Dim num_cols As Integer Dim column_header As ColumnHeader Dim list_item As ListItem Dim i As Integer Dim num_subitems As Integer Dim col_wid() As Single Dim X As Single Dim Y As Single Dim line_hgt As Single xmin = Printer.CurrentX ymin = Printer.CurrentY ' ****************** ' Get column widths. num_cols = lvw.ColumnHeaders.Count ReDim col_wid(1 To num_cols) ' Check the column headers. For i = 1 To num_cols col_wid(i) = _ Printer.TextWidth(lvw.ColumnHeaders(i).Text) Next i ' Check the items. num_subitems = num_cols - 1 For Each list_item In lvw.ListItems ' Check the item. If col_wid(1) < Printer.TextWidth(list_item.Text) _ Then _ col_wid(1) = Printer.TextWidth(list_item.Text) ' Check the subitems. For i = 1 To num_subitems If col_wid(i + 1) < _ Printer.TextWidth(list_item.SubItems(i)) _ Then _ col_wid(i + 1) = _ Printer.TextWidth(list_item.SubItems(i)) Next i Next list_item ' Add a column margin. For i = 1 To num_cols col_wid(i) = col_wid(i) + COL_MARGIN Next i ' ************************* ' Print the column headers. Printer.CurrentY = ymin + MARGIN Printer.CurrentX = xmin + MARGIN X = xmin + MARGIN For i = 1 To num_cols Printer.CurrentX = X Printer.Print FittedText( _ lvw.ColumnHeaders(i).Text, col_wid(i)); X = X + col_wid(i) Next i xmax = X + MARGIN Printer.Print line_hgt = Printer.TextHeight("X") Y = Printer.CurrentY + line_hgt / 2 Printer.Line (xmin, Y)-(xmax, Y) Y = Y + line_hgt / 2 ' Print the rows. num_subitems = num_cols - 1 For Each list_item In lvw.ListItems X = xmin + MARGIN ' Print the item. Printer.CurrentX = X Printer.CurrentY = Y Printer.Print FittedText( _ list_item.Text, col_wid(1)); X = X + col_wid(1) ' Print the subitems. For i = 1 To num_subitems Printer.CurrentX = X Printer.Print FittedText( _ list_item.SubItems(i), col_wid(i + 1)); X = X + col_wid(i + 1) Next i Y = Y + line_hgt * 1.5 Next list_item ymax = Y ' Draw lines around it all. Printer.Line (xmin, ymin)-(xmax, ymax), , B X = xmin + MARGIN / 2 For i = 1 To num_cols - 1 X = X + col_wid(i) Printer.Line (X, ymin)-(X, ymax) Next i End Sub' Return as much text as will fit in this width. Private Function FittedText(ByVal txt As String, ByVal wid _ As Single) As String Do While Printer.TextWidth(txt) > wid txt = Left$(txt, Len(txt) - 1) Loop FittedText = txt End Function
Private Sub mnuFilePrint_Click()
Printer.CurrentX = 1440
Printer.CurrentY = 1440 PrintListView ListView1 Printer.EndDoc
End SubPrivate Sub PrintListView(lvw As ListView)
Const MARGIN = 60
Const COL_MARGIN = 240Dim ymin As Single
Dim ymax As Single
Dim xmin As Single
Dim xmax As Single
Dim num_cols As Integer
Dim column_header As ColumnHeader
Dim list_item As ListItem
Dim i As Integer
Dim num_subitems As Integer
Dim col_wid() As Single
Dim X As Single
Dim Y As Single
Dim line_hgt As Single xmin = Printer.CurrentX
ymin = Printer.CurrentY ' ******************
' Get column widths.
num_cols = lvw.ColumnHeaders.Count
ReDim col_wid(1 To num_cols) ' Check the column headers.
For i = 1 To num_cols
col_wid(i) = _
Printer.TextWidth(lvw.ColumnHeaders(i).Text)
Next i ' Check the items.
num_subitems = num_cols - 1
For Each list_item In lvw.ListItems
' Check the item.
If col_wid(1) < Printer.TextWidth(list_item.Text) _
Then _
col_wid(1) = Printer.TextWidth(list_item.Text) ' Check the subitems.
For i = 1 To num_subitems
If col_wid(i + 1) < _
Printer.TextWidth(list_item.SubItems(i)) _
Then _
col_wid(i + 1) = _
Printer.TextWidth(list_item.SubItems(i))
Next i
Next list_item ' Add a column margin.
For i = 1 To num_cols
col_wid(i) = col_wid(i) + COL_MARGIN
Next i ' *************************
' Print the column headers.
Printer.CurrentY = ymin + MARGIN
Printer.CurrentX = xmin + MARGIN
X = xmin + MARGIN
For i = 1 To num_cols
Printer.CurrentX = X
Printer.Print FittedText( _
lvw.ColumnHeaders(i).Text, col_wid(i));
X = X + col_wid(i)
Next i
xmax = X + MARGIN Printer.Print
line_hgt = Printer.TextHeight("X")
Y = Printer.CurrentY + line_hgt / 2
Printer.Line (xmin, Y)-(xmax, Y)
Y = Y + line_hgt / 2 ' Print the rows.
num_subitems = num_cols - 1
For Each list_item In lvw.ListItems
X = xmin + MARGIN ' Print the item.
Printer.CurrentX = X
Printer.CurrentY = Y
Printer.Print FittedText( _
list_item.Text, col_wid(1));
X = X + col_wid(1) ' Print the subitems.
For i = 1 To num_subitems
Printer.CurrentX = X
Printer.Print FittedText( _
list_item.SubItems(i), col_wid(i + 1));
X = X + col_wid(i + 1)
Next i Y = Y + line_hgt * 1.5
Next list_item
ymax = Y ' Draw lines around it all.
Printer.Line (xmin, ymin)-(xmax, ymax), , B X = xmin + MARGIN / 2
For i = 1 To num_cols - 1
X = X + col_wid(i)
Printer.Line (X, ymin)-(X, ymax)
Next i
End Sub' Return as much text as will fit in this width.
Private Function FittedText(ByVal txt As String, ByVal wid _
As Single) As String
Do While Printer.TextWidth(txt) > wid
txt = Left$(txt, Len(txt) - 1)
Loop
FittedText = txt
End Function