LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default no workbooks open

Hi Simon

You can test the count when you try to open the userform of the add-in
But you can also try to set the activesheet and trap the error


Sub OpenUserform()
Dim asheet As Worksheet
Set asheet = Nothing
On Error Resume Next
Set asheet = ActiveSheet
On Error GoTo 0

If asheet Is Nothing Then
MsgBox "Error: There is no active worksheet.", _
vbOKOnly, "Hi there"
Exit Sub
Else
userform1.Show
End If
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Simon Shaw" <simonATsimonstoolsDOTcom wrote in message ...
thanks,

How do I get it to execute when a different workbook is closed?


"Ron de Bruin" wrote:

Note: that this also count the personal.xls workbook that is hidden

Dim wb As Workbook
Dim Num As Integer
Num = 0
For Each wb In Application.Workbooks
If wb.Windows(1).Visible Then
Num = Num + 1
End If
Next
MsgBox Num


--
Regards Ron de Bruin
http://www.rondebruin.nl


"ben" (remove this if mailing direct) wrote in message
...
simon
if workbooks.count = 0 then

'disable buttons
end if
--
When you lose your mind, you free your life.


"Simon Shaw" wrote:

When no workbooks are open, most toolbuttons and menu options in Excel are
disabled.

I have a menu and toolbar created by an add-in I built. How can I detect in
my addin that no workbooks are open so I can set the toolbuttons and menu
options to disabled?






 
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
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 doesn't open file in ThisWorkbook Tomu Excel Programming 0 May 7th 04 10:18 PM
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 08:08 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"