View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Edwin Tam (MS MVP) Edwin Tam (MS MVP) is offline
external usenet poster
 
Posts: 48
Default VBA or MACRO to prevent someone from printing the contents of an Excel worksheet

Place the following first two macros in the WORKSHEET you want to avoid someone from printing
Place the third macro below into a Module

Basically they does the following things
On activate of a worksheet
1) Disable the "Print" menu ite
2) Replace the Excel shortcut key Ctrl+p with a dummy macro (which contains nothing)
On deactivate of the worksheet
3) Reverse (1) and (2)

'-----Put in the worksheet-----------------------
Private Sub Worksheet_Activate(
Application.CommandBars(1).Controls("File").Contro ls("Print...").Enabled = Fals
Application.OnKey "^p", "dummy_macro
End Su

Private Sub Worksheet_Deactivate(
Application.CommandBars(1).Controls("File").Contro ls("Print...").Enabled = Tru
Application.OnKey "^p
End Su
'-----------------------------------------------------

'-----Put in a module-------------------------------
Private Sub dummy_macro(

End Su
'-----------------------------------------------------


Regards
Edwin Ta