I would like the active window of this workbook to be positioned in the upper left hand corner of the active display. This works with one monitor, but not with my configuration of 6-monitors (one video card).
I put the active Excel Window on each display one at a time and ran the following code:
Sub Display_WinAnchor()
ActiveWindow.WindowState = xlNormal
ActiveWindow.Left = 0
End Sub
Monitors 1, 3, 4, 5 are oriented as portrait.
When the code was run on monitors 3 & 5, the window moved to the left side of monitor 3.
When the code was run on monitors 1 & 4, the window moved to the left side of monitor 1.
Monitors 2,6 are oriented as landscape.
When the code was run on monitors 2 & 6, with the active Excel Window on the UPPER half, the window moved to the left side of monitor 3.
When the code was run on monitors 2 & 6, with the active Excel Window on the LOWER half, the window moved to the left side of monitor 1.
I do not use display tiling, I am simply extending the displays in the Windows 10 Display Settings. And it does not seem to be a primary monitor issue.
I can get all the configuration information through code I found here - https://wellsr.com/vba/2019/excel/calculate-screen-size-and-other-display-details-with-vba/
I added the following cases to the code:
Case "monitors" 'Number of Monitors
Result = GetSystemMetrics(SM_CMONITORS)
Case "displaynum" 'Display Device Number
Result = hMonitor
Case "windownum" 'Active Window Number
Result = hwnd
Now, if I run this code...
Sub Display_GetSpecs()
Debug.Print "Number Of Monitors ="; Screen("monitors")
Debug.Print "Name Of Display = "; Screen("displayname")
Debug.Print "Display Device Number ="; Screen("displaynum")
Debug.Print "Active Window Number ="; Screen("windownum")
Debug.Print "Display Horz PIXEL ="; Screen("pixelsx")
Debug.Print "Display Vert PIXEL ="; Screen("pixelsy")
Debug.Print "Display Horz INCHES ="; Screen("inchesx")
Debug.Print "Display Vert INCHES ="; Screen("inchesy")
Debug.Print "Display Horz POINTS ="; Screen("inchesx") * 72
Debug.Print "Display Vert POINTS ="; Screen("inchesy") * 72
End Sub
I get these results...
Number Of Monitors = 6
Name Of Display = \.\DISPLAY4
Display Device Number = 65545
Active Window Number = 526414
Display Horz PIXEL = 1440
Display Vert PIXEL = 2560
Display Horz INCHES = 13.3858267716535
Display Vert INCHES = 23.6220472440945
Display Horz POINTS = 963.779527559055
Display Vert POINTS = 1700.7874015748
Note... "Name Of Display" does not match what Windows 10 Display Settings is showing. Not sure why, but not sure I need it to find a fix to my problem. What I am mostly interested in is the "Display Device Number = 65545"
Is there a way through code to have ActiveWindow.Left work for a specific display? In this example, "Display Device Number = 65545".
