Fix Excel Runtime Error 1004 When Setting Workbook Window Width
Question details
The user needs to arrange multiple Excel workbooks without triggering Runtime Error 1004 when a VBA macro sets window dimensions.

- Product
- Microsoft Excel for Microsoft 365
- Device & OS
- not provided
- Scenario
- A VBA macro positions and resizes workbook windows to display multiple workbooks at once.
- Observed behavior
- Excel may display Runtime Error 1004 when the macro directly sets workbook window positions or sizes.
Open the workbooks you want to arrange in the same Excel instance and make sure their windows are visible. Open the VBA editor from Developer > Visual Basic and run macros only from trusted sources.
Use Windows.Arrange Instead of Setting Window Dimensions
Use Excel's built-in arrangement method when the goal is to display open workbook windows side by side or stacked.
Windows.Arrange lets Excel calculate the window positions and sizes instead of assigning width and position values manually. It can arrange other visible workbook windows in the same Excel instance, not just two selected workbooks.
In Excel, select Developer > Visual Basic, then open the module containing the macro that sets the window width.
Replace the manual window position and size assignments with the following command for side-by-side windows: Windows.Arrange ArrangeStyle:=xlVertical
To place workbook windows one above the other instead, use: Windows.Arrange ArrangeStyle:=xlHorizontal
Return to Excel and select Developer > Macros. Choose the edited macro and select Run, then check that the open workbook windows are arranged as intended.

Work With Excel Spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and support for common Excel formats, making it easy to move everyday workbook tasks to WPS. It does not fix errors in Microsoft Excel VBA, and macro compatibility may vary.

Frequently Asked Questions
How do I arrange Excel workbooks side by side with VBA?
Open the workbooks in the same Excel instance, then use Windows.Arrange ArrangeStyle:=xlVertical in your VBA macro.
How can I stack workbook windows instead?
Use Windows.Arrange ArrangeStyle:=xlHorizontal in the macro to arrange the visible workbook windows one above the other.
Will Windows.Arrange affect only the two workbooks I selected?
Not necessarily. Windows.Arrange can arrange other visible workbook windows in the same Excel instance, so check which workbooks are open before running the macro.
What if Runtime Error 1004 still appears?
In the VBA editor, inspect the line highlighted when the error occurs. Error 1004 has multiple possible causes, and replacing window sizing code addresses only this particular scenario.




