How to check if ANY excel workbook is open?

后端 未结 3 2012
刺人心
刺人心 2021-01-24 19:11

I have a VBA project in excel which hides the workbook in the background and only shows the userform, it works fine however, causes problems when other workbooks are open as it

3条回答
  •  暖寄归人
    2021-01-24 19:16

    I think, since 'ActiveWorkbook' can also be empty, the safest answer for VBA may be:

    Option Explicit
    
    Public Function IsAnyWorkbookOpen() As Boolean
        IsAnyWorkbookOpen = (Application.Workbooks.Count > 0)
    End Function
    
    Sub test()
        MsgBox ("IsAnyWorkbookOpen returns: " + CStr(IsAnyWorkbookOpen()))
    End Sub
    

提交回复
热议问题