Hi Jeff,
Since I can't
find a way (yet) to convince XL to ignore the Print click I'm sending a custom button approach. The new button will run the macro only.
Cut the Before Print macro and paste it into a module and rename it. I used:
Sub pmacro()
in this example.
Run the AddPrint sub. This will add asecond Print Icon (FaceId = 4) on the Standard Menu bar in position 5 with a 'ToolTip' of "Print with Macro". If having two Icons the same is acceptable then put AddPrint and DelPrint in the WorkbookOpen/Close
events. If not...then:
Click View,
Toolbars, Customize, New to add a new toolbar
named "Custom 1". (Note if you already have custom toolbars, name the new one and remember the name for the AddBluePrint & DelBluePrint subs),
Now drag the Second Print Icon to the Custom 1 toolbar. Right click and Edit Button Face to change it's look (I changed the backgroud to blue on mine). Close when done.
Now run DelPrint sub to clear the second Icon from the menu bar. Run AddBluePrint to add the new Icon to the menu bar and DelBluePrint to remove it. If all works well, put AddBluePrint and DelBluePrint in the Open/Close events and it will be there for
thisworkbook ONLY.
It's the only method I could find for
saving a custom face ID - storing it on a custom (hidden) toolbar.
Cool info on the
Arrays jindon thanks!
Learning lots about custom menus, xlDialogs, etc!
Are we having fun yet...? <G>
Cheers,
dr
VB: AutoLinked keywords will cause extra spaces before keywords. Extra spacing is NOT transferred when copy/pasting, but IS if the keyword uses "quotes".
Sub AddBluePrint()
Application.CommandBars("Custom 1").Visible = True
Application.CommandBars("Custom 1").Controls(1).Move Bar:=Application. _
CommandBars("Standard"), Before:=5
Application.CommandBars("Custom 1").Visible = False
End Sub
Sub DelBluePrint()
Application.CommandBars("Custom 1").Visible = True
Application.CommandBars("Standard").Controls(5).Move Bar:=Application. _
CommandBars("Custom 1")
Application.CommandBars("Custom 1").Visible = False
End Sub
Sub AddPrint()
Dim NewToolbar As CommandBar
Dim NewButton As CommandBarButton
Set NewToolbar = Application.CommandBars("Standard")
Set NewButton = NewToolbar.Controls.Add _
(Type:=msoControlButton, Id:=2950, Before:=5)
NewButton.FaceId = 4
NewButton.Caption = "Print with Macro"
NewButton.OnAction = "pmacro"
End Sub
Sub DelPrint()
Application.CommandBars("Standard").Controls.Item(5).Delete
End Sub
Sub r()
Application.CommandBars("Standard").Reset
End Sub