Events after printing??

goblin

Active Member
Joined
Apr 16, 2003
Messages
469
I'm trying to stop Excel from printing textboxes that contain only guidelines on how to use a workbook. Stopping Excel from printing is easy enough by turning of textbox visibility. My problem is turning on visibility again after printing. So far I have the code below (placed in the ThisWorkbook module). Now I need to know if some event fires AFTER printing so that I can turn visibility on again.

Code:
Sub TextBoxPrint(onOff As MsoTriState)
    Dim sh As Shape
    For Each sh In ActiveSheet.Shapes
        If sh.Type = msoTextBox Then
            sh.Visible = onOff
        End If
    Next
End Sub

Private Sub Workbook_BeforePrint(Cancel As Boolean)
    TextBoxPrint msoFalse
End Sub

Can anyone help? Or point out another way to do this?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
In design mode, if you right clicked on the TextBox and select properties, look for PrintObject, you can set that to True or False. Of course, you can set this properties through your code as well. This way you don't have to mess with the visibility.
 
Upvote 0
Hi goblin,

You can get an AfterPrint effect by using something along these lines:
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)

Cancel = True
'cancel main print

TextBoxPrint msoFalse

With ActiveSheet
    Application.EnableEvents = False
    'to stop this event being called again
    .PrintOut
    'print
    Application.EnableEvents = True
    'switch events back on
End With

TextBoxPrint msoTrue

End Sub
HTH

EDIT: Missed the second call to the routine
 
Upvote 0
jlo1976d, I already looked for some properties on the TextBox, but had no success in locating it. That is the reason I reverted to VBA. That is the method I usually use, e.g. when I don't want to print CommandButtons and such.

As to the OnTime method refered to by Juan Pablo, I had already thought of and discounted it, as I didn't like the notion of the textboxes reappearing some X seconds after printing (as I obviously have no idea how long the printing is going to take). Perhaps it is worth investigating how the callback stacks with printing in Excel, i.e. if I can just set the X seconds delay to something very short and hope the OnTime callback schedules after the printing run.

I like Richies implementation very much though. Does everything I want and is very intuitive and clear. Thanks for that one Richie!! :biggrin:

Goblin
 
Upvote 0

Forum statistics

Threads
1,216,178
Messages
6,129,326
Members
449,501
Latest member
Amriddin

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