Workbook_Open problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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

Private Sub Workbook_Open()
With Application.ThisWorkbook.Windows(1)
.Width = 275
.Height = 270
End With
End Sub
 
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
 
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.
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top