Controlling Window Size across multiple Monitors

HappsLucks

Board Regular
Joined
May 6, 2016
Messages
72
Hi,

I have a multi-sheet workbook which I designed on my 22" Wide Screen (16:9) monitor.
I have a code running that opens the book (and all sheets) in a neat window, placed strategically on my monitor.

My wife has a 17" normal (4:3) monitor. I had to remove this code to get the workbook to display properly on her monitor.
This got me thinking. If I share this workbook with others, is there a way that I can adapt this code so that my workbook displays in a "window" placed neatly on any monitor, any size, any aspect ratio, just as it does on my monitor? Effectively, could this code be more dynamic, calling the monitor size/aspect ratio and using these dimensions, to achieve this?

Here is the code.
Code:
Dim iMaxWidth As Integer
    Dim iMaxHeight As Integer
    Dim iStartX As Integer
    Dim iStartY As Integer
    Dim iDesiredWidth As Integer
    Dim iDesiredHeight As Integer


    iStartX = 143
    iStartY = 18
    iDesiredWidth = 980
    iDesiredHeight = 750
    


    With Application
        .WindowState = xlMaximized
        iMaxWidth = Application.Width
        iMaxHeight = Application.Height


        iMaxWidth = iMaxWidth - iStartX
        iMaxHeight = iMaxHeight - iStartY
        If iDesiredWidth > iMaxWidth Then
            iDesiredWidth = iMaxWidth
        End If
        If iDesiredHeight > iMaxHeight Then
            iDesiredHeight = iMaxHeight
        End If


        .WindowState = xlNormal
        .Top = iStartY
        .Left = iStartX
        .Width = iDesiredWidth
        .Height = iDesiredHeight
        
    End With

Thanks!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
OK, so it seems I have managed to find a solution that actually works on both my 16:9 monitor, and the other 4:3 monitor. I just need to test it on different size monitors, but it looks like it works!
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top