Attribute VB_Name = "ModPrintClasses"
Public Function DistribuirDatos(NumCols As Integer, Cantidad As Integer)

Dim Recorre, NumPerCol As Integer

NumPerCol = Round((Cantidad / NumCols), 0)

FormPrint1.ListPrint.View = lvwReport

For Recorre = 1 To NumCols
  FormPrint1.ListPrint.ColumnHeaders.Add , , "COLUMNA" & CStr(Recorre), FormPrint1.ListPrint.Width / NumCols
Next

Call IngresaDatosPorCol(NumPerCol, NumCols, Cantidad)

End Function

Public Function IngresaDatosPorCol(NumPerColumna As Integer, CantidadCols As Integer, CantidadTot As Integer)

Dim MaxAncho(0 To 7) As Integer
Dim Tamanio, Recorre, Buscador, Actual As Integer
Dim MaxPathString As String
Dim AnchoTotal As Integer
Dim ColAct As Long

For Recorre = 0 To CantidadCols - 2
  
  Buscador = Recorre * NumPerColumna + 1
  MaxAncho(Recorre) = Len(Form1.ListView1.ListItems(Buscador).Text)
  
  For Actual = Buscador To (Recorre + 1) * NumPerColumna
    If Len(Form1.ListView1.ListItems(Actual).Text) > MaxAncho(Recorre) Then
      MaxAncho(Recorre) = Len(Form1.ListView1.ListItems(Actual).Text)
    End If
   Next
Next

'busco en los elementos restantes
MaxAncho(Recorre) = Len(Form1.ListView1.ListItems((Recorre + 1) * NumPerColumna).Text)

For Actual = Actual + 1 To CantidadTot
  If Len(Form1.ListView1.ListItems(Actual).Text) > MaxAncho(Recorre) Then
    MaxAncho(Recorre) = Len(Form1.ListView1.ListItems(Actual).Text)
  End If
Next

For Recorre = 0 To CantidadCols - 1
  AnchoTotal = AnchoTotal + MaxAncho(Recorre)
Next

For Recorre = 0 To CantidadCols - 1
  ColAct = (FormPrint1.ListPrint.Width * MaxAncho(Recorre)) / AnchoTotal
  FormPrint1.ListPrint.ColumnHeaders.Item(Recorre + 1).Width = Round(ColAct, 0)
Next

End Function
