ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If no workbooks are open? (https://www.excelbanter.com/excel-programming/356696-if-no-workbooks-open.html)

jayklmno

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

Tom Ogilvy

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


jayklmno

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



All times are GMT +1. The time now is 01:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com