Resuming code after closing a print preview

D

DarrenW

Hello all,

I am using the following code in to call a print preview from a
userform

Private Sub JobPrint()

Me.Hide
ThisWorkbook.Sheets("PSheet").PrintPreview
Me.Show

End Sub

When I click on the print button on my userform a sub "builds" a
worksheet that contains all the information I want to print. The sub
then hides the userform and calls a print preview of the worksheet.

When I close the print preview (by clicking the Close button) and
Excel shows the userform again, it doesn't return to the print sub
from which it was called, so the print sub which called the print
preview does'nt complete its execution.

Any ideas or help would be great.

Thanks in advance.

DarrenW
 
B

Bob Kilmer

Darren,
(Modeless userforms were introduced with Excel 2000, so this advice may not
apply to you if you are using an earlier version.)

Me.Show opens the userform modally - that is, it requires the user to
acknowledge or dismiss the dialog before code execution continues.

Me.Show is equivalent to Me.Show vbModal

Either use Me.Show vbModeless, which may allow code execution to continue,
or open the form later, after the print code finishes.

Bob Kilmer
 
Joined
Aug 29, 2020
Messages
1
Reaction score
0
Hi Bob,

I just try your code and it works well.

Private Sub CmdCTK_Click()

Me.Hide

' ThisWorkbook.Sheets("PSheet").PrintPreview

ActiveSheet.PrintPreview ' we can use this code when we need to preview another sheet

Me.Show (vbModeless)

End Sub


Thank you.
Cakadola
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top