Excel Hints

Results 1 to 3 of 3

Thread: Maximize Excel window

  1. #1

    Maximize Excel window

    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 = xlMaximized
    it 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!!

  2. #2
    Administrator
    2nd VP-Knowledge Base
    VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    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:
    [vba]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[/vba]
    Hope this helps




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  3. #3
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •