ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Workbook_Open problem (https://www.excelbanter.com/excel-programming/294677-workbook_open-problem.html)

TroyH

Workbook_Open problem
 
Why do I keep getting this error

Run-time error '1004'
Unable to set the Width property of the Windows clas

In my ThisWorkbook object I have the following code

Private Sub Workbook_Open(
With ActiveWindo
.Width = 27
.Height = 27
End Wit
End Su

This only errors out when I open Excel with the file. If Excel is already open, no error

The worksheet is not protected

Thanks.

Tom Ogilvy

Workbook_Open problem
 
Try

Private Sub Workbook_Open()
With Application.ThisWorkbook.Windows(1)
.Width = 275
.Height = 270
End With
End Sub

--
Regards,
Tom Ogilvy


"TroyH" wrote in message
...
Why do I keep getting this error:

Run-time error '1004':
Unable to set the Width property of the Windows class

In my ThisWorkbook object I have the following code:

Private Sub Workbook_Open()
With ActiveWindow
.Width = 275
.Height = 270
End With
End Sub

This only errors out when I open Excel with the file. If Excel is already

open, no error.

The worksheet is not protected.

Thanks.




TroyH

Workbook_Open problem
 
Thanks Tom for the reply. It works as well, but I keep getting that error. It will always appear if the last window opened before closing Excel is maximized. If the last window is normal, then there is no problem

Any ideas



Tom Ogilvy

Workbook_Open problem
 
Well, this is the first time you mentioned anything about maximized windows.

The obvious solution is to check if it is maximized or forget the check and
make in normal

Private Sub Workbook_Open()
With Application.ThisWorkbook.Windows(1)
.WindowState = xlNormal
.Width = 275
.Height = 270
End With
End Sub

--
Regards,
Tom Ogilvy


"TroyH" wrote in message
...
Thanks Tom for the reply. It works as well, but I keep getting that error.

It will always appear if the last window opened before closing Excel is
maximized. If the last window is normal, then there is no problem.

Any ideas?





TroyH

Workbook_Open problem
 
Thanks Tom. It seems I had the same idea as you. When I checked to see if the windows was normal or maximized and changed accordingly, it worked. D'Oh! I will learn as time goes on

Thanks again.


All times are GMT +1. The time now is 12:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com