Workbook_Open problem

T

TroyH

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.
 
T

Tom Ogilvy

Try

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

TroyH

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
 
T

Tom Ogilvy

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 said:
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.
 
T

TroyH

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.
 
Top