Adjusting excel for multiple monitors with secondary on the LEFT

adamdavi3s

New Member
Joined
Feb 3, 2011
Messages
2
Hi All!

Long time lurker, first time poster!

I've compiled a set of VBA from various places on the web, to allow users to manipulate their excel session to take account of multiple monitors.

This works perfectly for people with the second screen on the right of their main, however I can not get it working for people with them on the left!

The key piece of code I am having problems with, is application.width

The working code is:

Code:
Option Explicit

Declare Function GetSystemMetrics _
    Lib "user32.dll" ( _
    ByVal nIndex As Long) _
As Long

Const SM_CXSCREEN = 0
Const SM_CYSCREEN = 1
Const SM_CXVIRTUALSCREEN = 78
Const SM_CYVIRTUALSCREEN = 79
Const SM_XVIRTUALSCREEN = 76
Const SM_YVIRTUALSCREEN = 77
Public dtop As Long, dleft As Long, dheight As Long, dwidth As Long



Sub side_by_side()
  
    With Application
        .WindowState = xlNormal
        .Top = 0
        .Left = 0
        .Height = GetSystemMetrics(SM_CYSCREEN) - 225
        .Width = GetSystemMetrics(SM_CXVIRTUALSCREEN) - 500
    End With

      Windows.Arrange ArrangeStyle:=xlVertical
End Sub
Which works perfectly for a right hand screen, give or take a few pixels.

When altering it for the left hand screen:

Code:
Option Explicit

Declare Function GetSystemMetrics _
    Lib "user32.dll" ( _
    ByVal nIndex As Long) _
As Long

Const SM_CXSCREEN = 0
Const SM_CYSCREEN = 1
Const SM_CXVIRTUALSCREEN = 78
Const SM_CYVIRTUALSCREEN = 79
Const SM_XVIRTUALSCREEN = 76
Const SM_YVIRTUALSCREEN = 77
Public dtop As Long, dleft As Long, dheight As Long, dwidth As Long



Sub side_by_side()
  
    With Application
        .WindowState = xlNormal
        .Top = 0
        .Left = (GetSystemMetrics(SM_CXVIRTUALSCREEN) - GetSystemMetrics(SM_CXSCREEN) - 315) * -1
        .Height = GetSystemMetrics(SM_CYSCREEN) - 225
        .Width = GetSystemMetrics(SM_CXVIRTUALSCREEN) - 500
    End With

      Windows.Arrange ArrangeStyle:=xlVertical
End Sub
It just will NOT work! It places the application perfectly on the left screen and corrects the height as expected, however it will not stretch the screen onto the primary monitor!!!
Even if I hard code this figure to 10,000 it just refuses to work!


Any ideas??

many thanks in advance!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

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