PDA

View Full Version : Maximize Excel window



mqdias
11-15-2007, 10:42 AM
Hi,

I have a UserForm with a "Print" button. when i click it opens a print preview, but, because i minimized the Excel window at workbook open, with the code:
Application.WindowState = xlMaximizedit doesn't maximize the window and therefore i can't see the 'print preview'.

Here is the code for the commandbutton:

Private Sub CommandButton8_Click()
Module6.Time
UserForm1.Hide
End Sub


'PRINT PREVIEW
Function Time()
Application.OnTime Now + TimeSerial(0, 0, 0.5), "showForm"
End Function

Thanks for any help!!

malik641
11-15-2007, 12:36 PM
Hi,

A few notes:
1. TimeSerial's arguments accepts Integers (you have a double for the Seconds parameter). And by the looks of it, you don't need the Application.OnTime method if the form will show up in half-a-second.
2. You don't need the function "Time" because that 1 line of code can be executed in your CommandButton8 procedure.
3. For your main problem, you can check if Excel's window is minimized, then act appropriately.

Example code:
Private Sub CommandButton8_Click()
UserForm1.Hide
Call showForm
End Sub

Public Sub showForm()
' Check if Excel is minimized
If (Application.WindowState = xlMinimized) Then _
Application.WindowState = xlMaximized
' Print preview...
End Sub
Hope this helps

mqdias
11-16-2007, 12:51 PM
Malik,

Thank you soo much for you patiance!!!! I'll will try this and see what happens... But thank you for you answer and for giving a new look to the code. It looks much more good!