Block printing via menu "Print" with macro

0

I wonder if there is any way to block the printing of a worksheet from the File-Print (Ctrl + P) menu or the printer icon through a macro. Well, I made a macro that when you push a button it will do a behavior in the worksheet and have it printed automatically.

    
asked by anonymous 18.08.2018 / 01:55

1 answer

0

Enter the code in EstaPastaDeTrabalho or ThisWorkbook in English:

WhereWorkbook_BeforePrint(CancelAsBoolean)isused.

PrivateSubWorkbook_BeforePrint(CancelAsBoolean)IfimprimirThenCancel=FalseElseMsgBox("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
    
24.08.2018 / 14:29