How detect if any workbooks are open?

C

Chet

I have code to change my appplication.width from double width to
single width. The code works fine with the exception of when I don't
have a workbook actually open. Is there a way to test whether any
workbooks are currently open? Then maybe I can skip the line that
fails.

Here is my code. It is failing at the 2nd line when there isn't a
workbook open.
Sub TOOLBAR_MK_SCRN_SINGLE_WIDTH_MOVE_RIGHT_TO_LEFT()
'SHRINKS SIZE OF DOUBLE WIDE SCREEN TO SINGLE WIDE SCREEN AND THEN
MOVES ACTIVEWORKBOOK
'FROM RIGHT SIDE TO THE LEFT SIDE.

If Application.WindowState = xlMaximized Then
Application.WindowState = xlNormal
If ActiveWindow.WindowState = xlMaximized Then
ActiveWindow.WindowState = xlNormal <-fails here

ActiveWindow.WindowState = xlNormal
With ActiveWindow
.Top = 0
.Left = -2
End With
Application.Width = 958
ActiveWindow.Height = 654
Application.Height = 768
End Sub

Thanks in advance.

Chet
 
P

Peter T

The code might fail
ActiveWindow.WindowState = xlNormal
if there is no ActiveWindow or ActiveWorkbook but there might be oner or
more hidden workbooks, eg Personal.xls

Rather than checking for open workbooks could do

If Not ActiveWindow Is Nothing Then
or
If Not ActiveWorkbook Is Nothing Then

Regards,
Peter T
 

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

Top