Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default How detect if any workbooks are open?

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 396
Default How detect if any workbooks are open?

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default How detect if any workbooks are open?

On Jun 27, 2:51*pm, Wigi 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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default How detect if any workbooks are open?

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" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Detect if an excel file is open JCP[_2_] Excel Programming 1 September 1st 07 11:34 AM
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 Excel Programming 2 June 15th 04 03:21 AM
how to detect if user has a dialogbox open Von Shean Excel Programming 2 January 12th 04 02:35 PM
How to detect Acrobat Distiller open Bill Li Excel Programming 0 August 6th 03 02:25 AM
Detect if file is open Chad[_6_] Excel Programming 4 July 9th 03 05:05 AM


All times are GMT +1. The time now is 05:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"