Vídeo recomendado
https://youtu.be/diWPPPhW-9E

Exportar dados listbox para planilha

Fórum para dúvidas sobre os fundamentos da linguagem de programação Visual Basic no contexto do VBA
NERI INACIO
Colaborador
Colaborador
Mensagens: 62
Registrado em: Sáb Fev 27, 2016 7:31 pm

Re: Exportar dados listbox para planilha

Mensagem por NERI INACIO »

Eu faço um pouco diferente, tenho um filtro e depois exporto. Porém exporto para planilha excel.


Disable adblock

This site is supported by ads and donations.
If you see this text you are blocking our ads.
Please consider a Donation to support the site.


lima.luiz
Colaborador
Colaborador
Mensagens: 14
Registrado em: Ter Jun 12, 2018 10:08 pm

Re: Exportar dados listbox para planilha

Mensagem por lima.luiz »

NERI INACIO escreveu: Seg Jun 18, 2018 7:20 am Amigo já conseguiu resolver a questão?
ainda não Neri, pode ajudar?


NERI INACIO
Colaborador
Colaborador
Mensagens: 62
Registrado em: Sáb Fev 27, 2016 7:31 pm

Re: Exportar dados listbox para planilha

Mensagem por NERI INACIO »

Bom dia amigo

Desculpe, não tinha visto a sua notificação, estou na correria. Assim que vi eu lhe respondo.....
Para vc entender: Os dados que estão no listbox são enviados para uma planilha de Excel para ser impresso depois. Veja o código... no caso enviei para a minha planilha 17 que será impressa.

Código: Selecionar todos

Private Sub btnimprimir_Click()
 ' reexibir as planilhas - eu deixo sempre ocultas quando não imprimo
    Worksheets("PrintD").Visible = xlSheetHidden
    Worksheets("PrintD").Visible = True

Worksheets("PrintD").Activate

    Dim lngListLoop As Long
    Dim lngRowNum As Long, lngColNum As Long

    lngRowNum = 1
    lngColNum = 1
    
'cria varíavel para contagem da linha a ser preenchida
Dim Nlin
'cria uma variável para contar as linhas da lstlista
Dim Cont

'limpa a região com dados anteriores
'Plan17.Range("A1:j1000").ClearContents

'linha inicial da planilha que carregará os dados
Nlin = 5

'preenche as outras linhas até o fim da lstlista
For Cont = 1 To Me.LstLista.ListCount - 1
    Plan17.Range("A" & Nlin + 1) = Me.LstLista.List(Cont, 0) ' COD
    Plan17.Range("B" & Nlin + 1) = Me.LstLista.List(Cont, 1) ' MES
    Plan17.Range("C" & Nlin + 1) = Me.LstLista.List(Cont, 2) ' ANO
    Plan17.Range("D" & Nlin + 1) = Me.LstLista.List(Cont, 4) ' CLIENTE
    Plan17.Range("E" & Nlin + 1) = Me.LstLista.List(Cont, 6) ' CIA
    Plan17.Range("F" & Nlin + 1) = Me.LstLista.List(Cont, 7) ' TIPO
    Plan17.Range("G" & Nlin + 1) = Me.LstLista.List(Cont, 8) ' R$
    Plan17.Range("H" & Nlin + 1) = Me.LstLista.List(Cont, 9) 'VCTO
Nlin = Nlin + 1
Next

        
    With PrintD
        


' Define a área de impressão
Dim lRow As Long
lRow = Cells(Cells.Rows.Count, "H").End(xlUp).Row
ActiveSheet.PageSetup.PrintArea = Range("A1", "H" & lRow).Address


' FORMATAR DADOS
            
       Cont = Worksheets("PrintD").UsedRange.Rows.Count + 1 'Contas os registros
       Plan17.Activate
        'Application.Dialogs(xlDialogPrint).Show ' isto escolhe a impressora
        
        ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False

   
    
    ' oculta planilha
      Worksheets("PrintD").Visible = xlSheetVeryHidden
      Worksheets("Inicio").Activate

End Sub


Disable adblock

This site is supported by ads and donations.
If you see this text you are blocking our ads.
Please consider a Donation to support the site.


Responder