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.
Thanks!
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!