Removing the Print options

jasgot

New Member
Joined
Jul 16, 2002
Messages
30
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
  5. 2010
Platform
  1. Windows
I have a macro that prints after doing some work for me.

I would like to disable the print options from the menu and tool bars so the user must click my button in the sheet.

I've tried these two peices of code, neither addresses the user pressing <ctrl>-P and both leave the print option removed from excel for other workbooks even if I re enable them in an Auto_Close macro.


Application.CommandBars(1).FindControl(ID:=109, recursive:=True).Enabled = False
'Application.CommandBars(1).FindControl(ID:=2521, recursive:=True).Enabled = False
'Application.CommandBars("File").Controls("Print...").Enabled = False
'Application.CommandBars("Standard").Controls(6).Enabled = False


Can someone shed some light on a better way to force users to use *my* print macro?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
What does "btt" stand for?

Anyways, what you're looking for is:

Application.OnKey "^p", "[Code name you want to run heah]"

Want to do it in AutoOpen so it's defined for everything or via an application wrapper.

g-
 
Upvote 0
Back to Top

Thanks for the control p fix, I still have the problem turning the print menu options back on.
 
Upvote 0
Don't understand. The print option is still there in your File drop down?

What you could do is manually rebuild the menu on the fly. It's not that hard though it's 3am where I am so I'm going to sleep. If this is indeed your question, then send me a private message and I'll post back the answer on how to do it. Basically, you'd redefine Print to run your macro instead of opening the dialog box. Does this upon app startup.

g-
 
Upvote 0
Try this.

Put in the ThisWorkbook module :-

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If OKtoPrint Then
Cancel = False
Else
MsgBox "You can only print by clicking the Special Print button"
Cancel = True
End If
End Sub

Put this in a normal module :-

Public OKtoPrint As Boolean

Sub PrintIt()
OKtoPrint = True
End Sub

Sub DontPrintIt()
OKtoPrint = False
End Sub


In your macro that does the printing, call PrintIt before your print instruction and call DontPrintIt after it.
 
Upvote 0
Thanks!
That is very elegant!

And it works :)
 
Upvote 0
I would like say thank you for I have benefited from this post.

Try this.

Put in the ThisWorkbook module :-

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If OKtoPrint Then
Cancel = False
Else
MsgBox "You can only print by clicking the Special Print button"
Cancel = True
End If
End Sub

Put this in a normal module :-

Public OKtoPrint As Boolean

Sub PrintIt()
OKtoPrint = True
End Sub

Sub DontPrintIt()
OKtoPrint = False
End Sub


In your macro that does the printing, call PrintIt before your print instruction and call DontPrintIt after it.
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,259
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top