ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   add a print key only (https://www.excelbanter.com/excel-programming/284177-add-print-key-only.html)

mikegospo[_3_]

add a print key only
 

I asked a question earlier about restoring my command menu. I got it t
work. I am using this program. I know want to make it just leave
print icon of some type. Here is the code I am using

Private Sub Workbook_Activate()
Dim bar As CommandBar
For Each bar In Application.CommandBars
bar.Enabled = False
Next
End Sub

Private Sub Workbook_Deactivate()
Dim bar As CommandBar
For Each bar In Application.CommandBars
bar.Enabled = True
Next
End Sub


I guess I need one in between to add the print menu.
Mik

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com

~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements

Ron de Bruin

add a print key only
 
Hi mikegospo

You can use something like this or use the CTRL-P shortcut with your other code to print


Sub MakeToolBar()
Dim bar As CommandBar
On Error Resume Next
Application.CommandBars("MyToolBar").Delete
On Error GoTo 0
For Each bar In Application.CommandBars
bar.Enabled = False
Next
With Application.CommandBars.Add(Name:="myToolBar", Position:=msoBarTop, MenuBar:=False)
.Protection = msoBarNoCustomize
' Prevent users from accessing the Add or Remove Buttons menu

' this will add a default Excel button
.Controls.Add Type:=msoControlButton, ID:=4
.Visible = True
End With
End Sub


Sub DeleteToolBar()
Dim bar As CommandBar
On Error Resume Next
Application.CommandBars("MyToolBar").Delete
On Error GoTo 0
For Each bar In Application.CommandBars
bar.Enabled = True
Next
End Sub


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"mikegospo" wrote in message ...

I asked a question earlier about restoring my command menu. I got it to
work. I am using this program. I know want to make it just leave a
print icon of some type. Here is the code I am using

Private Sub Workbook_Activate()
Dim bar As CommandBar
For Each bar In Application.CommandBars
bar.Enabled = False
Next
End Sub

Private Sub Workbook_Deactivate()
Dim bar As CommandBar
For Each bar In Application.CommandBars
bar.Enabled = True
Next
End Sub


I guess I need one in between to add the print menu.
Mike


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements




Tom Ogilvy

add a print key only
 
see code inline:

--
Regards,
Tom Ogilvy

Private Sub Workbook_Activate()
Dim bar As CommandBar
For Each bar In Application.CommandBars
bar.Enabled = False
Next

On Error Resume Next
Commandbars("PrintBar").Delete
On Error goto 0
Application.CommandBars.Add(Name:="PrintBar").Visi ble = True
Application.CommandBars("PrintBar").Controls.Add _
Type:=msoControlButton, ID:=4, Befo=1

End Sub



Private Sub Workbook_Deactivate()
Dim bar As CommandBar
For Each bar In Application.CommandBars
bar.Enabled = True
Next

On Error Resume Next
Commandbars("PrintBar").Delete
On Error goto 0
End Sub

--

Regards,
Tom Ogilvy

------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to

creating financial statements



mikegospo[_4_]

add a print key only
 

Didnt work Tom, this is what I put in.

Private Sub Workbook_Activate()
Dim bar As CommandBar
For Each bar In Application.CommandBars
bar.Enabled = False
Next
On Error Resume Next
CommandBars("PrintBar").Delete
On Error GoTo 0
Application.CommandBars.Add(Name:="PrintBar").Visi ble = True
Application.CommandBars("PrintBar").Controls.Add _
Type:=msoControlButton, ID:=4, Befo=1
End Sub

Private Sub Workbook_Deactivate()
Dim bar As CommandBar
For Each bar In Application.CommandBars
bar.Enabled = True
Next
On Error Resume Next
CommandBars("PrintBar").Delete
On Error GoTo 0
End Sub

It hangs on the last CommandBars command
CommandBars("PrintBar").Delete


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements

Tom Ogilvy

add a print key only
 
Add Application before the Commandbars. Worked for me.

Private Sub Workbook_Activate()
Dim bar As CommandBar
For Each bar In Application.CommandBars
bar.Enabled = False
Next
On Error Resume Next
Application.CommandBars("PrintBar").Delete
On Error GoTo 0
Application.CommandBars.Add(Name:="PrintBar").Visi ble = True
Application.CommandBars("PrintBar").Controls.Add _
Type:=msoControlButton, ID:=4, Befo=1
End Sub

Private Sub Workbook_Deactivate()
Dim bar As CommandBar
For Each bar In Application.CommandBars
bar.Enabled = True
Next
On Error Resume Next
Application.CommandBars("PrintBar").Delete
On Error GoTo 0
End Sub

--
Regards,
Tom Ogilvy

"mikegospo" wrote in message
...

Didnt work Tom, this is what I put in.

Private Sub Workbook_Activate()
Dim bar As CommandBar
For Each bar In Application.CommandBars
bar.Enabled = False
Next
On Error Resume Next
CommandBars("PrintBar").Delete
On Error GoTo 0
Application.CommandBars.Add(Name:="PrintBar").Visi ble = True
Application.CommandBars("PrintBar").Controls.Add _
Type:=msoControlButton, ID:=4, Befo=1
End Sub

Private Sub Workbook_Deactivate()
Dim bar As CommandBar
For Each bar In Application.CommandBars
bar.Enabled = True
Next
On Error Resume Next
CommandBars("PrintBar").Delete
On Error GoTo 0
End Sub

It hangs on the last CommandBars command
CommandBars("PrintBar").Delete


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to

creating financial statements



mikegospo[_7_]

add a print key only
 

Now it hangs where I have the asterisk?


Private Sub Workbook_Activate()
Dim bar As CommandBar
For Each bar In Application.CommandBars
bar.Enabled = False
Next
On Error Resume Next
**Application.CommandBars("PrintBar").Delete
On Error GoTo 0
Application.CommandBars.Add(Name:="PrintBar").Visi ble = True
Application.CommandBars("PrintBar").Controls.Add _
Type:=msoControlButton, ID:=4, Befo=1
End Sub

Private Sub Workbook_Deactivate()
Dim bar As CommandBar
For Each bar In Application.CommandBars
bar.Enabled = True
Next
On Error Resume Next
Application.CommandBars("PrintBar").Delete
On Error GoTo 0
End Sub

End Sub


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements

mikegospo[_8_]

add a print key only
 

I get a VB error and it stops on that line. Sorry to keep bothering you
but now my excel is messed up and I lost all tool bars and cant get
them restored. Sorry I feel like a boob.
Mike


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements

Tom Ogilvy

add a print key only
 
Do you have Break on unhandled errors selected in VBA in the tools menu
under the options, then under the General Tab?

If you have Break on all errors, that is your problem.

--
Regards,
Tom Ogilvy

"mikegospo" wrote in message
...

I get a VB error and it stops on that line. Sorry to keep bothering you
but now my excel is messed up and I lost all tool bars and cant get
them restored. Sorry I feel like a boob.
Mike


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to

creating financial statements




All times are GMT +1. The time now is 07:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com