Results 1 to 4 of 4

Thread: Create New Excel Window - size and position are TOTALY WRONG!
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Aug 2011
    Location
    Slovenia, Europe
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry Create New Excel Window - size and position are TOTALY WRONG!

    I'm working on a small project in Excel (Office 365) where I'm starting to lose my mind, since code is behaving crazy!

    The idea is to open two windows of same Excel workbook at the same time, side-by-side, with specific window dimensions. I prepared an example of new workbook "Book1.xlsm" with two Worksheets ("Sheet1" and "Sheet2"). After pressing the "CommandButton1", there should be two windows of the Workbook placed on my monitor side by side with next properties:


    • Left window showing "Sheet1" (Top=0, Left=0, Height=880, Width=960)
    • Right window showing "Sheet2" (Top=0, Left=960, Height=880, Width=960)


    I have two-monitor setup with screen resolution 19201200 each. You can see that I'm trying to place each window on one half of the monitor (2 960 px = 1920 px).



    BUT(!) when the code is executed, the size and position of both windows are all WRONG:


    • Left window showing "Sheet1" (Top=-2, Left=-2, Height=1173, Width=1280)
    • Right window showing "Sheet2" (Top=-2, Left=1278, Height=1173, Width=1280)



    Does anyone knows why is Excel ignoring size properties set in code and positions windows on these bizarre coordinates? Can someone please check the code and posts the results here? Thank you in advance!

    Here is link to file Book1.xlsm in my Dropbox and here is also the code behind "CommandButton1":



    Code:
    Private Sub CommandButton1_Click()
    
    
    Application.ScreenUpdating = False
    
    
    'Get rid of all open windows to start at 1. Easier than determining which windows are open and processing them.
    
    Do Until Windows.Count = 1
    
        Windows(Windows.Count).Close
    
    Loop
    
    
    Application.WindowState = xlMaximized
    
    ActiveWindow.WindowState = xlMaximized
    
    Application.WindowState = xlNormal
    
    
    
    
    
    'Create 1 more for a total of 2 windows.
    
    ActiveWindow.NewWindow
    
    ActiveWindow.DisplayGridlines = False
    
    ActiveWorkbook.Windows.Arrange ArrangeStyle:=xlVertical
    
    
    
    For Each wnWin In Windows
    
    
        Select Case wnWin.WindowNumber
    
      
        'Right window: "Sheet2"
    
            Case Is = 2
    
                wnWin.Activate
    
                Sheets("Sheet2").Select
    
                With wnWin
    
                    .WindowState = xlNormal
    
                    .Top = 1
    
                    .Left = 960
    
                    .Height = 880
    
                    .Width = 960
    
                    .DisplayGridlines = False
    
                    .DisplayHeadings = False
    
                 End With
    
    
    
        'Left window: "Sheet2"
    
            Case Is = 1
    
                wnWin.Activate
    
                Sheets("Sheet1").Select
    
                Sheets("Sheet2").Activate
    
                With wnWin
    
                    .WindowState = xlNormal
    
                    .Top = 0
    
                    .Left = 0
    
                    .Height = 880
    
                    .Width = 960
    
                    .DisplayGridlines = False
    
                    .DisplayHeadings = False
    
                End With
    
        End Select
    
    
    
    
    Next wnWin
    
    
    
    Application.ScreenUpdating = True
    
    
    
    End Sub






    Disclamer: since I'm quite of noob in VBA, I'm gathering code parts from all over the internet. The code above is modified code, found on Stack Overflow.

  2. #2
    New Member
    Join Date
    Aug 2011
    Location
    Slovenia, Europe
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb Re: Create New Excel Window - size and position are TOTALY WRONG!

    To make shorter version of my original post: it is maybe easier if I make a poll here:

    Please test button in this file and post the result. I hope you can estimate the size of both windows ...

    Thanks.

  3. #3
    New Member
    Join Date
    Aug 2011
    Location
    Slovenia, Europe
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Create New Excel Window - size and position are TOTALY WRONG!

    Bump.

    Please make a test in my previous (or original) post. Thank you!

  4. #4
    New Member
    Join Date
    Aug 2011
    Location
    Slovenia, Europe
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Create New Excel Window - size and position are TOTALY WRONG!

    Quote Originally Posted by morzapo View Post
    Bump.

    Please make a test in my previous (or original) post. Thank you!

    Hi,

    has anyone tried the code?

    BR
    morzapo

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •