Assaf
Assaf

Reputation: 89

Change Excel Windows sizes to half the screen

I have 4 Excel Windows:

I want to Change the sizes of my windows in that way:

**I guess for access to Microsoft Visual Basic for Applications - PERSONAL.XLSB [break] I need a reference to windows system library, but i believe it should be possible

Any ideas please?

Upvotes: 1

Views: 10715

Answers (2)

Naveen Kumar
Naveen Kumar

Reputation: 2006

May be this will help you.

Sub SetWindowSize1()
    Application.WindowState = xlNormal
    Application.Top = 25
    Application.Left = 25
    Application.Width = 300
    Application.Height = 200
End Sub

And to set the window width and height as per the screen size, here you can see the code: https://www.ozgrid.com/forum/index.php?thread/142634-vba-to-automatically-resize-user-form-depending-on-screen-resolution/

Code to loop through VBA windows:

Sub ListWindows()
Dim wn As Excel.Window
For Each wn In Application.Windows
    MsgBox wn.Caption
Next wn
End Sub

Upvotes: 0

Michał Turczyn
Michał Turczyn

Reputation: 37377

You can try below code:

Sub ChangeWindowSize()
    ' get size of a screen
    Application.WindowState = xlMaximized
    windWidth = Application.width
    windHeight = Application.height
    ' set size and location of a main workbook
    Application.WindowState = xlNormal
    Application.Top = 0
    Application.Left = 0
    Application.width = windWidth / 2
    Application.height = windHeight

    Call OpenOtherWorkBookAndSetSize(windWidth, windHeight)
End Sub

Sub OpenOtherWorkBookAndSetSize(windWidth As Variant, windHeight As Variant)
    Dim appExcel As Application
    Dim objWorkbook As Workbook
    Dim i As Integer

    'create new excel application object
    Set appExcel = New Application
    'open other workbook
    Set objWorkbook = appExcel.Workbooks.Open("path to the file")
    ' just example setting
    appExcel.WindowState = xlNormal
    appExcel.Top = 0
    appExcel.Left = windWidth / 2
    appExcel.width = windWidth / 2
    appExcel.height = windHeight
    appExcel.Visible = True
End Sub

It will split your screen into halves :) Now you can modify further this code :)

Example result:

enter image description here

Upvotes: 2

Related Questions