Link to home
Start Free TrialLog in
Avatar of Roger
RogerFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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--
Avatar of ThomasMcA2
ThomasMcA2

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.
Avatar of Roger

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of ThomasMcA2
ThomasMcA2

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
Avatar of Roger

ASKER

For people like me who have never heard of AutoHotkey, if you google 'AutoHotKey script' there is enough on page 1 to get started.
Avatar of Roger

ASKER

Thanks for good advice!
Kelvin