Print Preview

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.
 
J

JLGWhiz

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?
 
J

JLGWhiz

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
 
E

Eddie_SP

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.
 
D

Dave Peterson

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
 
J

JLGWhiz

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.
 
E

Eddie_SP

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.
 
E

Eddie_SP

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
 
E

Eddie_SP

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
 
D

Dave Peterson

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.)
 

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