Link to home
Start Free TrialLog in
Avatar of itsmevic
itsmevicFlag for United States of America

asked on

Excel 2010: Minimize Excel

Hello Experts -

     For some reason the code that I have is not fully minimizing outlook when the macro is engaged.  When I click the button, I'd like just the macro its self to remain and to minimize Excel completely in the background.  Where am I going wrong with my code?

Sheet 1:
Private Sub btnFrmopen_Click()
ActiveWindow.WindowState = xlMinimized
UserForm1.Show vbModeless

End Sub

Open in new window


Module 1:
Private Declare Function GetForegroundWindow Lib "User32.dll" () As Long

Private Declare Function GetWindowLong _
  Lib "User32.dll" Alias "GetWindowLongA" _
    (ByVal hWnd As Long, _
     ByVal nIndex As Long) _
  As Long
               
Private Declare Function SetWindowLong _
  Lib "User32.dll" Alias "SetWindowLongA" _
    (ByVal hWnd As Long, _
     ByVal nIndex As Long, _
     ByVal dwNewLong As Long) _
  As Long

Private Const WS_THICKFRAME As Long = &H40000
Private Const GWL_STYLE As Long = -16

Public Sub MakeFormResizable()

  Dim lStyle As Long
  Dim hWnd As Long
  Dim RetVal
  
    hWnd = GetForegroundWindow
  
    'Get the basic window style
     lStyle = GetWindowLong(hWnd, GWL_STYLE) Or WS_THICKFRAME

    'Set the basic window styles
     RetVal = SetWindowLong(hWnd, GWL_STYLE, lStyle)

End Sub

Open in new window


Your suggestions are greatly welcomed! Thank you.
Avatar of Mike in IT
Mike in IT
Flag of United States of America image

What exactly is happening when you click on the button?
Avatar of itsmevic

ASKER

The macro launches as it should, but Excel does not minimize to the toolbar.
Avatar of Norie
Norie

itsmevic

Could you attach a sample workbook with the code you posted?

I've tried installing the code you've posted in a blank workbook with no luck.

By the way, how exactly is the code in Module1 being called/triggered/executed?
Sample workbook attached.
Desktop-Widget-Checkoff-List-1.xlsm
ASKER CERTIFIED SOLUTION
Avatar of Mike in IT
Mike in IT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect, that worked Mike, thank you!