How to reduce height of xl application window - close to the xl Ribbon - and lock the height when that reduction is in force?

I seek to reduce the height of the Excel Application window for certain procedures in my Excel project.
I have a partial solution (via Application.Height = 151), but if I reduce the height to less than 151, the xl ribbon vanishes. I would like Application.height to be quite tight to the underside of the xl ribbon (I guess about 120)

Secondly, is there a way of locking/unlocking the height of the Application window so I have more control?
Else (?) detecting a change in window height as an event and over-riding that dimension change when I want it locked?


Sub setExcelWindowFeatures()  
    Dim appHeight As Long    
            'Change height of application window with appHeight
    appHeight = 151  'minimum height - else ribbon disappears
    With Application
        .WindowState = xlNormal
        .Top = 1
        .Left = 30
        .Width = 600
        .Height = appHeight
        With .ActiveWindow  'hide worksheets when application height is minimised
            If appHeight < 300 Then
                .Top = -700 'cannot hide all sheets, so place them out of window view when application
                .Top = 1
            End If        
        End With

    End With
End Sub
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It looks like your code already does what you're asking to do. Does your code not work?

If you need more control over application windows, try using AutoHotkey. It has great window controls, and can even launch Excel macros via the same automation techniques that work from Word or Access.
Kelvin4Author Commented:
Thomas, thanks..
My problems are: reduce Application.height from 151 to about 125, so the application neatly fits around the xl Ribbon. At present (with Application.height = 151) there are about 30 height units protruding below the xl Ribbon. However (para 1) reduction of Application height below 150 leads to the ribbon disappearing.

B.. Irrespective of A (above) , can I prevent Application.height being altered manually, by the user dragging the application handle and expanding its size (ie locking the Application.height).


"A" sounds like an issue with XL itself, and how it manages objects in a non-maximized window. Other than controlling the height, width, and location of the window, I think you're stuck with whatever XL wants to do with its own controls/objects.

Regarding "B", I have never heard of a tool that can lock down the size of an application window. An AutoHotkey script could come close to that by retrieving the current size of the window, and changing it to the desired size if it's not already that size. That could run in a loop that checks the window size every few seconds.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kelvin4Author Commented:
For people like me who have never heard of AutoHotkey, if you google 'AutoHotKey script' there is enough on page 1 to get started.
Kelvin4Author Commented:
Thanks for good advice!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.