Vejabem
20-01-2018 02:20:59
Pessoal, boa noite!
O código abaixo serve para gerar um relatório a partir de uma ListView. Gostaria de adaptar esse mesmo código para gerar um relatório a partir de uma ListBox. Será que é possível? Alguém pode me ajudar nesse sentido, por gentileza?
Desde já, obrigado!
----------------------
On Error Resume Next
Dim i As Integer
Dim j As Integer
Dim Regs As Integer
Dim linha As Long
Dim caminho As String
Application.ScreenUpdating = False
Regs = Me.ListView1.ListItems.Count
Sheets("Imprimir").Select
Range("A2:W30000").Select
Selection.ClearContents
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Range("A2").Select
'Laço das linhas e colunas para extrair os valores da listview e passar para o planilha
For i = 1 To Regs
linha = i + 1
Cells(linha, 1) = Me.ListView1.ListItems(i)
For j = 1 To Me.ListView1.ColumnHeaders.Count - 1
Cells(linha, j + 1) = Me.ListView1.ListItems(i).ListSubItems(j)
Next
Next
'Formata área de impressão
Range("A1:W" & linha).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlHairline
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlHairline
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlHairline
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlHairline
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlHairline
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlHairline
End With
Range("A" & linha & ":W" & linha).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -4.99893185216834E-02
.PatternTintAndShade = 0
End With
' Define área de impressão
Range("A1:W" & linha).Select
ActiveSheet.PageSetup.PrintArea = "$A$1:$W$" & linha
Application.ScreenUpdating = True
Range("A2").Select
MsgBox "Relatório gerado com sucesso!", vbInformation, "GERAR RELATÓRIO"
O código abaixo serve para gerar um relatório a partir de uma ListView. Gostaria de adaptar esse mesmo código para gerar um relatório a partir de uma ListBox. Será que é possível? Alguém pode me ajudar nesse sentido, por gentileza?
Desde já, obrigado!
----------------------
On Error Resume Next
Dim i As Integer
Dim j As Integer
Dim Regs As Integer
Dim linha As Long
Dim caminho As String
Application.ScreenUpdating = False
Regs = Me.ListView1.ListItems.Count
Sheets("Imprimir").Select
Range("A2:W30000").Select
Selection.ClearContents
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Range("A2").Select
'Laço das linhas e colunas para extrair os valores da listview e passar para o planilha
For i = 1 To Regs
linha = i + 1
Cells(linha, 1) = Me.ListView1.ListItems(i)
For j = 1 To Me.ListView1.ColumnHeaders.Count - 1
Cells(linha, j + 1) = Me.ListView1.ListItems(i).ListSubItems(j)
Next
Next
'Formata área de impressão
Range("A1:W" & linha).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlHairline
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlHairline
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlHairline
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlHairline
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlHairline
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlHairline
End With
Range("A" & linha & ":W" & linha).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -4.99893185216834E-02
.PatternTintAndShade = 0
End With
' Define área de impressão
Range("A1:W" & linha).Select
ActiveSheet.PageSetup.PrintArea = "$A$1:$W$" & linha
Application.ScreenUpdating = True
Range("A2").Select
MsgBox "Relatório gerado com sucesso!", vbInformation, "GERAR RELATÓRIO"