PC Review


Reply
Thread Tools Rate Thread

How detect if any workbooks are open?

 
 
Chet
Guest
Posts: n/a
 
      27th Jun 2008
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
 
Reply With Quote
 
 
 
 
Wigi
Guest
Posts: n/a
 
      27th Jun 2008
Perhaps

Application.Workbooks.Count



--
Wigi
http://www.wimgielis.be = Excel/VBA, soccer and music


"Chet" wrote:

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

 
Reply With Quote
 
Chet
Guest
Posts: n/a
 
      28th Jun 2008
On Jun 27, 2:51*pm, Wigi <W...@discussions.microsoft.com> wrote:
> Perhaps
>
> Application.Workbooks.Count
>
> --
> Wigihttp://www.wimgielis.be= Excel/VBA, soccer and music
>
>
>
> "Chet" wrote:
> > 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- Hide quoted text -

>
> - Show quoted text -


That did the trick!.. thx.. chet
 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      29th Jun 2008
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

"Chet" <(E-Mail Removed)> wrote in message
news:29328208-c013-4bc2-aaab-(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Workbooks.Open() / method 'open' of object 'workbooks' failed Luc Dindeman Microsoft Excel Crashes 0 25th Mar 2009 12:03 PM
Excel2007; workbooks.count is not counting all open workbooks greg.campeau Microsoft Excel Programming 2 2nd Aug 2008 08:37 PM
Multiple workbooks open -- closing workbooks =?Utf-8?B?SmFuZXQgUGFuaWdoZXR0aQ==?= Microsoft Excel Discussion 3 13th Nov 2007 05:43 PM
Excel 2003 Workbooks.Open with CorruptLoad=xlRepairFile fails on Excel 5.0/95 file due to Chart, with Error 1004 Method 'Open' of object 'Workbooks' failed Frank Jones Microsoft Excel Programming 2 15th Jun 2004 03:21 AM
Linked workbooks will not update without having all workbooks open =?Utf-8?B?S2F0aGVyaW5l?= Microsoft Excel Misc 0 26th Feb 2004 05:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:43 AM.