Block printing via "Print" macro menu

Asked

Viewed 685 times

0

I wonder if there is any way to block the printing of a sheet by the File-Print menu (Ctrl+P) or by the printer icon, through a macro. Yes, I made a macro that when pressing a button it will make a behavior in the spreadsheet and will have printed automatically.

1 answer

0

Enter the code in EstaPastaDeTrabalho or ThisWorkbook in English:

Esta pasta de Trabalho

In which the event Workbook_BeforePrint(Cancel As Boolean) is used.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
    If imprimir Then
        Cancel = False
    Else
        MsgBox ("Você não possui permissão para imprimir.")
        Cancel = True
    End If
End Sub

And a test to print with the code in a Module:

Public imprimir As Boolean
Sub teste_impressao()
    imprimir = True
    Planilha1.PrintOut
End Sub
Sub teste_nao_impressao()
    Planilha1.PrintOut
End Sub

Browser other questions tagged

You are not signed in. Login or sign up in order to post.