Share via


Control size of Excel window openned with PoweShell?

Question

Friday, October 10, 2014 9:46 PM

Is there a way to specify the window size of a visible Excel window opened in a PowerShell script - to keep it from openning full-screen? 

All replies (5)

Saturday, October 11, 2014 12:01 PM ✅Answered

Hi,

is this what you are looking for?:

Start-Process excel.exe -WindowStyle Maximized

Saturday, October 11, 2014 8:49 PM ✅Answered

or perhaps:

    Start-Process excel.exe -WindowStyle Normal

Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.


Monday, October 13, 2014 3:35 AM ✅Answered

Hi San,

You can also try to use the method Application.WindowState  to specify the vision size:

$objExcel = New-Object -ComObject Excel.Application;
$objExcel.WindowState= "xlMaximized"
$objExcel.visible=$true
$ExcelFilesLocation = "d:\test.xlsx"
$UserWorkBook = $objExcel.Workbooks.Open($ExcelFilesLocation) 
$objExcel.Quit()

If there is anything else regarding this issue, please feel free to post back.

If you have any feedback on our support, please click here.

Best Regards,

Anna Wang

TechNet Community Support


Monday, October 13, 2014 6:14 PM ✅Answered | 1 vote

If you use Anna's method, you can get very explicit control over the window size. If you try to set specific size using Excel's Top, Left, Height, and Width properties, be warned that these are measured in points, not pixels. To convert pixel value to point, multiply by 0.75.

The following code sets Excel to 800x600 window size, 20 pixels down and to the right of the upper left screen corner.

$objExcel = New-Object -ComObject Excel.Application
$objExcel.Visible = $true
#Can't set size unless windowstate is Normal
$objExcel.WindowState = "xlNormal"
$objExcel.Left = .75*20
$objExcel.Top = .75*20
$objExcel.Width = .75*800
$objExcel.Height = .75*600

Thursday, October 23, 2014 3:38 AM

Hi San,

I’m writing to just check in to see if the suggestions were helpful. If you need further help, please feel free to reply this post directly so we will be notified to follow it up.

If you have any feedback on our support, please click here.

Best Regards,

Anna Wang

TechNet Community Support