Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Andrew
 
Posts: n/a
Default Checking to see how many workbooks are visible

I've written a macro I need to incorporate into a spreadsheet to send out to
other users in the business. At the moment the only time it seems to crash is
if there are no workbooks visible / active when it is set running (which
could happen).

How do I check how many workbooks are currently visible before the rest of
the macro starts running?

Thanks,

Andrew
  #2   Report Post  
Rowan
 
Posts: n/a
Default

One way:

Sub bks()
Dim i As Integer
Dim bk As Workbook
For Each bk In Workbooks
If bk.Name < "PERSONAL.XLS" Then
i = i + 1
End If
Next bk
MsgBox "Open Books: " & i
End Sub

Or:

Sub winds()
Dim i As Integer
Dim wnd As Window
For Each wnd In Windows
If wnd.Visible = True Then
i = i + 1
End If
Next wnd
MsgBox "Visible Windows: " & i
End Sub

Hope this helps
Rowan

"Andrew" wrote:

I've written a macro I need to incorporate into a spreadsheet to send out to
other users in the business. At the moment the only time it seems to crash is
if there are no workbooks visible / active when it is set running (which
could happen).

How do I check how many workbooks are currently visible before the rest of
the macro starts running?

Thanks,

Andrew

  #3   Report Post  
Andrew
 
Posts: n/a
Default

The second one does the trick.

Thanks,

Andrew

"Rowan" wrote:

One way:

Sub bks()
Dim i As Integer
Dim bk As Workbook
For Each bk In Workbooks
If bk.Name < "PERSONAL.XLS" Then
i = i + 1
End If
Next bk
MsgBox "Open Books: " & i
End Sub

Or:

Sub winds()
Dim i As Integer
Dim wnd As Window
For Each wnd In Windows
If wnd.Visible = True Then
i = i + 1
End If
Next wnd
MsgBox "Visible Windows: " & i
End Sub

Hope this helps
Rowan

"Andrew" wrote:

I've written a macro I need to incorporate into a spreadsheet to send out to
other users in the business. At the moment the only time it seems to crash is
if there are no workbooks visible / active when it is set running (which
could happen).

How do I check how many workbooks are currently visible before the rest of
the macro starts running?

Thanks,

Andrew

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
Checking if sheet is visible LAF Excel Discussion (Misc queries) 1 August 9th 05 09:20 PM
checking other pages and workbooks for repeating numbers? Done Right Excel Discussion (Misc queries) 0 July 24th 05 01:01 PM
Consolidate different sheets to different workbooks markx Excel Worksheet Functions 3 April 26th 05 03:30 PM
Freeze Pane problem in shared workbooks JM Excel Discussion (Misc queries) 1 February 1st 05 12:04 AM
Workbooks...I'll try this again... Markster Excel Discussion (Misc queries) 10 December 7th 04 10:12 PM


All times are GMT +1. The time now is 04:16 AM.

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

About Us

"It's about Microsoft Excel"