Print Preview

  • Thread starter Thread starter Eddie_SP
  • Start date Start date
E

Eddie_SP

My UserForm takes the whole screen. I have many CommandButtons, and one of
them is "Print Preview".

I don't want the user to see the sheet (it's an "auto_open"), all controls
will be done by using the UserForm.

I have this:

Private Sub CommandButton6_Click()
On Error Resume Next
Worksheets(1).Select
ActiveSheet.PrintPreview
Me.Hide
End Sub

But it's not working. It freezes Excel, and all I have to do is Ctrl + Alt +
Del.

Can some help me? I tried searching the past topics, but none of them really
helped me.
 
You have me confused. If you do not want the sheet displayed, why do you
call print preview? What is the purpose of calling print preview at that
point?
 
The Me keyword refers to the object holding the code which can be a general
module, a sheet module or a form module. So if you want the button to hide:

Private Sub CommandButton6_Click()
On Error Resume Next
Worksheets(1).Select
ActiveSheet.PrintPreview
Me.CommandButton6.Hide
End Sub
 
Hi JLGWhiz !

The purpose is to see the final document already filled out.
It's a standard document. So at the end, after giving all the data, I want
to have a preview of what the user have done, if it's "ok" press button
"Print", if it's not "ok" press button "Correct document".

But always my UserForm will be on Top.

Tks.
 
Try hiding the userform first:

Private Sub CommandButton6_Click()
me.hide
with worksheets(1)
.visible = xlsheetvisible
.PrintPreview
.visible = xlsheethidden
end with
Me.show
End Sub
 
Should use visible property for controls.

Private Sub CommandButton6_Click()
On Error Resume Next
Worksheets(1).Select
ActiveSheet.PrintPreview
Me.CommandButton6.Visible = False
End Sub

I assume you know how to make it visible when you need it again.
 
Hi Dave,

Thank you very much for your help !

It worked the way I wanted.
But there is an error at end:

"UNABLE TO SET VISIBLE PROPERTY OF THE WORKSHEET CLASS".

Can you help on that?

Thank you once again !

Eddie.
 
By the way...

My workbook is not protected.



Dave Peterson said:
Try hiding the userform first:

Private Sub CommandButton6_Click()
me.hide
with worksheets(1)
.visible = xlsheetvisible
.PrintPreview
.visible = xlsheethidden
end with
Me.show
End Sub
 
Dave Peterson said:
Try hiding the userform first:

Private Sub CommandButton6_Click()
me.hide
with worksheets(1)
.visible = xlsheetvisible
.PrintPreview
.visible = xlsheethidden
end with
Me.show
End Sub
 
Glad you found the solution.

I'm betting that you typed the code instead of copy|pasting from the newsgroup
post. (And you made a typo--I don't see a difference between your solution and
my suggestion.)
 
Back
Top