如何检查任何excel工作簿是否打开? [英] How to check if ANY excel workbook is open?

查看:155
本文介绍了如何检查任何excel工作簿是否打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在excel中有一个VBA项目,该项目将工作簿隐藏在后台,并且仅显示用户窗体,但是工作正常,但是在打开其他工作簿时也会出现问题,因为它也会隐藏它们.为了防止这种情况,我试图找到一种在代码中放置if语句的方法,该方法检查启动时是否打开了任何excel工作簿.这可能吗?我在网上只能找到是否知道打开的文件名的方法.

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 hides them also. To prevent this I am trying to find some method of placing an if statement in the code which checks if any excel workbook is open at the time of start-up. Is this possible? All I can find online is how to check this if the open file name is known.

推荐答案

我认为,由于"ActiveWorkbook"也可以为空,因此VBA的最安全答案可能是:

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

这篇关于如何检查任何excel工作簿是否打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆