Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default If no workbooks are open?

I am working with an addin and if triggered from the menu, with no workbooks
open, how can I check to see if there are any workbooks open and if not,
prompt for one?

Thanks,
Jay
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default If no workbooks are open?

Sub ccc()
Dim bk As Workbook
Dim w As Window
If Workbooks.Count = 0 Then
'none open
MsgBox "Open a workbook"
Exit Sub
Else
' check for any visible
bVisible = False
For Each bk In Workbooks
For Each w In bk.Windows
Debug.Print w.Caption, w.Visible
If w.Visible = True Then

bVisible = True
End If
Next
Next
End If
if bVisible = false then
msgbox "Open a workbook"
exit sub
End if
' more code
End Sub

--
Regards,
Tom Ogilvy

"jayklmno" wrote:

I am working with an addin and if triggered from the menu, with no workbooks
open, how can I check to see if there are any workbooks open and if not,
prompt for one?

Thanks,
Jay

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default If no workbooks are open?

Thanks! I thought it would involve the workbooks.count, but when I tried it,
even thought no workbooks were visible, it had 1 for a count. But, that's
what your visible check is for... Thanks again!

"Tom Ogilvy" wrote:

Sub ccc()
Dim bk As Workbook
Dim w As Window
If Workbooks.Count = 0 Then
'none open
MsgBox "Open a workbook"
Exit Sub
Else
' check for any visible
bVisible = False
For Each bk In Workbooks
For Each w In bk.Windows
Debug.Print w.Caption, w.Visible
If w.Visible = True Then

bVisible = True
End If
Next
Next
End If
if bVisible = false then
msgbox "Open a workbook"
exit sub
End if
' more code
End Sub

--
Regards,
Tom Ogilvy

"jayklmno" wrote:

I am working with an addin and if triggered from the menu, with no workbooks
open, how can I check to see if there are any workbooks open and if not,
prompt for one?

Thanks,
Jay

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
When I open Excel, workbooks open automatically. How can I stop t Rhealbird Excel Discussion (Misc queries) 2 February 23rd 06 10:08 AM
workbooks.open function fails to open an existing excel file when used in ASP, but works in VB. san Excel Programming 1 January 3rd 06 03:22 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
Workbooks.Open closes other workbooks S. Daum Excel Programming 1 August 21st 03 07:47 PM
Workbooks.Open / .Open Text - How do you stop the .xls addition? Dave[_20_] Excel Programming 2 July 31st 03 04:03 AM


All times are GMT +1. The time now is 09:21 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"