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

Imprimir Planilha

Fórum para dúvidas sobre os fundamentos da linguagem de programação Visual Basic no contexto do VBA
Luciano021273
Colaborador
Colaborador
Mensagens: 59
Registrado em: Ter Mai 31, 2016 3:41 pm

Imprimir Planilha

Mensagem por Luciano021273 »

Boa tarde a todos!

Tenho uma planilha com um userform

Quando inicio a planilha a rotina chama meu userform e a plan fica invisivel deixando somente o userform

Mas quando preciso imprimir preciso que minha plan volte e após a impressão ele oculte novamente, deixando somente o userform aparente,

a não ser se de de imprimir com a plan oculta assim resolveria meu problema... segue o codigo que uso hoje, e em anexo estou enviando a planilha para testes,

codigo:

Application.Visible = True ' traz a plan


Dim IMPRI As Worksheet
Set IMPRI = Worksheets("Papel_de_Medidas")
Range("B2").Select

If cx_nome_cliente.Value = "" Then
MsgBox " SELECIONE ALGUM NOME e GERE ORÇAMENTO PARA PODER IMPRIMIR!", , ""
Exit Sub
End If
Plan24.Select
Range("B2").Select

C_AGENDA_DE_MEDIDAS.Hide
Application.Dialogs(xlDialogPrintPreview).Show
C_AGENDA_DE_MEDIDAS.Show

' Sheets("Papel_de_Medidas").Quit >>>>>>>>>testei não funcionou
Exit Sub


' Sheets("Papel_de_Medidas").Visible = False >>>>>>>> testei não funcionou



se alguém puder me ajudar, a fazer funcionar agradeço...

atenciosamente,
Anexos
para teste de impressão.rar
(127.7 KiB) Baixado 239 vezes


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.


Avatar do usuário
Rafael Monteiro
Consultor
Consultor
Mensagens: 277
Registrado em: Seg Nov 28, 2011 8:27 am
Localização: Sorocaba - SP
Contato:

Re: Imprimir Planilha

Mensagem por Rafael Monteiro »

Luciano,

Pelo eu entendi aqui, você precisa apenas colocar

Código: Selecionar todos

Application.Visible = True 
no inicio do código da impressão. E no fim do código você adiciona

Código: Selecionar todos

Application.Visible = False


Luciano021273
Colaborador
Colaborador
Mensagens: 59
Registrado em: Ter Mai 31, 2016 3:41 pm

Re: Imprimir Planilha

Mensagem por Luciano021273 »

Bom dia, Rafael!

Pensei que dessa forma iria funcionar, mas não da quando estou somente com o formulário aberto e vou imprimir ele some tudo, fica em tempo de execução e some tudo, para aparecer novamente, tenho que reiniciar o pc para abrir o formulário novamente,
será que tem outra forma? Não entendo muito de vba sou leigo,

att,


Avatar do usuário
Rafael Monteiro
Consultor
Consultor
Mensagens: 277
Registrado em: Seg Nov 28, 2011 8:27 am
Localização: Sorocaba - SP
Contato:

Re: Imprimir Planilha

Mensagem por Rafael Monteiro »

Bom dia Luciano,

Fiz um ajuste no código. Copie e cole no código do botão 'Imprimir Medidas' e veja se funciona.

Código: Selecionar todos

Private Sub btpPAPELMEDIDAS_Click() ''''########### gera papel de medidas

'*** FOI NECESSÁRIO CRIAR UMA CONDIÇÃO PARA  HAVER UMA VERIFICAÇÃO ANTES DE INICIAR O CÓDIGO DE IMPRESSÃO
If Application.Visible = False Then
Application.Visible = True
End If

    
'Application.ScreenUpdating = False

Worksheets("Papel_de_Medidas").Select
Range("B7").Select

'CARREGA INFORMAÇÕES PARA PAPEL DE MEDIDAS para imprimir
'-------------------------------------------------
'LIMPA OS CAMPOS
Plan24.Range("b7:l7").Select
Selection.ClearContents
Plan24.Range("b9:n9").Select
Selection.ClearContents
Plan24.Range("b11:n11").Select
Selection.ClearContents
Plan24.Range("b13:l13").Select
Selection.ClearContents
Plan24.Range("b15").Select
Selection.ClearContents
Plan24.Range("p3:p15").Select
Selection.ClearContents


Dim PM As Worksheet
Set PM = Worksheets("Papel_de_Medidas")
'Range("B2").Select

If cx_nome_cliente.Value = "" Then
MsgBox " SELECIONE ALGUM NOME PARA GERAR PAPEL DE MEDIDA!", , ""

'*** DEIXA A PLANILHA INVISIVEL SE NÃO SELECIONAR AILGUM NOME PARA GERAR PAPEL DE MEDIDA
Application.Visible = False

Exit Sub
End If

On Error GoTo continue

'*** DEIXA A PLANILHA VISIVEL PARA IMPRESSÃO
Application.Visible = True

'INSERE A PLANILHA
PM.Cells(7, 12) = Me.cmbnome_funcionario.Value
PM.Cells(9, 2) = Me.txtFcodcliente.Value
PM.Cells(9, 4) = Me.cx_nome_cliente.Value
PM.Cells(9, 10) = Me.txtDataCompromisso.Value
PM.Cells(9, 12) = VBA.Format(Me.cx_hora_compromisso.Value, "HH:MM")
PM.Cells(9, 14) = Me.cx_tel_celular.Value
PM.Cells(11, 2) = Me.cx_tel_fixo.Value
PM.Cells(11, 4) = Me.cx_endereço.Value
PM.Cells(11, 10) = Me.cx_numero.Value
PM.Cells(11, 12) = Me.cx_ap.Value
PM.Cells(11, 14) = Me.cx_Bloco.Value
PM.Cells(13, 2) = Me.cx_predio.Value
PM.Cells(13, 6) = Me.cx_Bairro.Value
PM.Cells(13, 12) = Me.cx_cidade.Value
PM.Cells(15, 2) = Me.cx_aproximidade.Value
PM.Cells(3, 16) = Me.ComboBox1.Value
PM.Cells(4, 16) = Me.ComboBox2.Value
PM.Cells(5, 16) = Me.ComboBox3.Value
PM.Cells(6, 16) = Me.ComboBox4.Value
PM.Cells(7, 16) = Me.ComboBox5.Value
PM.Cells(8, 16) = Me.ComboBox6.Value
PM.Cells(9, 16) = Me.ComboBox7.Value
PM.Cells(10, 16) = Me.ComboBox8.Value
PM.Cells(11, 16) = Me.ComboBox9.Value
PM.Cells(12, 16) = Me.ComboBox10.Value
PM.Cells(13, 16) = Me.ComboBox11.Value
PM.Cells(14, 16) = Me.ComboBox12.Value



''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
MsgBox "DESEJA IMPRIMIR O PAPEL DE MEDIDAS?", , ""
cmb_pesquisa.SetFocus
continue:


''''''''''#########################    AQUI PRECISO DE AJUDA  ###################################################################################

                                                            
                                                                
                                                                
                                                                Dim IMPRI As Worksheet
                                                                
                                                                
                                                              
                                                                Range("B2").Select
                                                                
                                                                If cx_nome_cliente.Value = "" Then
                                                                MsgBox " SELECIONE ALGUM NOME e GERE ORÇAMENTO PARA PODER IMPRIMIR!", , ""
                                                                Exit Sub
                                                                End If
                                                                Plan24.Select
                                                                Range("B2").Select
                                                                
    
                                                                 C_AGENDA_DE_MEDIDAS.Hide
                                                                    Application.Dialogs(xlDialogPrintPreview).Show
                                                                     Application.Visible = False
                                                                   C_AGENDA_DE_MEDIDAS.Show
                                                                   
                                                                '   Sheets("Papel_de_Medidas").Quit
                                                               

                                                                Exit Sub
                                                                
                                                                
                                                               
                                                                
                                                                
                                                                  
                                                                  
       
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.


Luciano021273
Colaborador
Colaborador
Mensagens: 59
Registrado em: Ter Mai 31, 2016 3:41 pm

Re: Imprimir Planilha [ RESOLVIDO ]

Mensagem por Luciano021273 »

professor, Rafael!

Funcionou legal, muito obrigado!!!! era exatamente oque precisava...
só esta dando uma travada, vou verificar, mas esta resolvido

atenciosamente,


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