Disable toolbar print command in Excel 2003?

Margate

New Member
Joined
Mar 15, 2013
Messages
21
Hello Everyone,

I built a sheet in Excel 2010 that contains the following VB code:

Code:
 	 		 			 			 				Private Sub Workbook_Open()
Application.CommandBars.FindControl(ID:=2521).Enabled = False
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.CommandBars.FindControl(ID:=2521).Enabled = True
End Sub




this works fine in 2010 but now the sheet needs to run in Excel 2003. The problem
is that when I open the sheet in 2003 I am met with the following error message:

Run-time error '91':
Object variable or With block variable not set

I am just trying to disable the toolbar printer icon so that it cannot be pressed!
In 2010 the above code fades the icon out disabling it.

I only want the user to print using a button that has a macro attached to it already that will print just 1 set page that has the page breaks set to the area I want to print. If the user presses the toolbar print icon 47 pages will be printed out instead of just the 1 that they need!

Any help is much appreciated.

Regards,

Margate
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hello John_w,

I do not know why the above code did not work but in the end I used the code below (in case anyone else may find this handy code):

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Cancel = True
MsgBox "To print please use the purple print buttons!", vbExclamation, "Print Canceled"
End Sub

Sub PrintPageOne()
Application.EnableEvents = False
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate:=True
Application.EnableEvents = True
End Sub

The same thing but a different way of going about it!
 
Upvote 0

Forum statistics

Threads
1,216,823
Messages
6,132,920
Members
449,768
Latest member
LouBa

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