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?

Thanks
Kelvin

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
            Else
                .Top = 1
            End If        
        End With

    End With
End Sub
Adjust-xl-window-fram-around-xl-ribbon--
Kelvin4Asked:
Who is Participating?
 
ThomasMcA2Commented:
Gotcha

"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.
0
 
ThomasMcA2Commented:
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.
0
 
Kelvin4Author Commented:
Thomas, thanks..
My problems are:
A..to 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).

Kelvin
0
 
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.
0
 
Kelvin4Author Commented:
Thanks for good advice!
Kelvin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.