跳到主要內容

如何快速檢查文件(工作簿)是否在Excel中打開或關閉?

在Excel的日常工作中,您同時打開多個工作簿進行工作,但是有時,數百個工作簿可能會讓您想起某個特定的工作簿是打開還是關閉。 放棄一種一一檢查文件的傳統方法,在這裡,我向您介紹一些技巧,以快速找到工作簿是打開還是關閉。

檢查工作簿是通過​​VBA打開還是關閉

使用Kutools for Excel檢查工作簿是否已打開或關閉 好主意3


檢查工作簿是通過​​VBA打開還是關閉

這是一個VBA代碼,您可以運行該代碼檢查特定的工作簿是否打開或關閉。

1。 按 Alt + F11鍵 打開鑰匙 Microsoft Visual Basic for Applications 窗口。

2。 點擊 插入 > 模塊 然後將VBA複製並粘貼到新 模塊 窗口。

VBA:檢查工作簿是否打開或關閉

Function IsWorkBookOpen(Name As String) As Boolean
    Dim xWb As Workbook
    On Error Resume Next
    Set xWb = Application.Workbooks.Item(Name)
    IsWorkBookOpen = (Not xWb Is Nothing)
End Function

Sub Sample()
    Dim xRet As Boolean
    xRet = IsWorkBookOpen("combine.xlsx")
    If xRet Then
        MsgBox "The file is open", vbInformation, "Kutools for Excel"
    Else
        MsgBox "The file is not open", vbInformation, "Kutools for Excel"
    End If
End Sub

3.然後按 F5 鍵以運行此vba,並彈出一個對話框,提醒您特定的工作簿是否打開。
doc檢查文件是否打開1     doc檢查文件是否打開2

小提示: 在上述VBA中,“結合”是您要檢查的工作簿名稱,您可以根據需要進行選擇。


使用Kutools for Excel檢查工作簿是否已打開或關閉

如果您不熟悉VBA,則可以通過以下方式檢查是否打開了工作簿: Excel的Kutools,帶有 導航 窗格,這將有助於您在窗格的工作簿列表中清晰地查看所有打開的工作簿。

Excel的Kutools, 與以上 300 方便的功能,使您的工作更加輕鬆。 

免費安裝 Kutools for Excel,請執行以下操作:

1。 點擊 庫工具 > 導航 啟用導航窗格。 看截圖:
doc檢查文件是否打開3

2。 然後點擊 工作簿和工作表 按鈕以展開窗格以轉到 工作簿和工作表 部分。 您可以在上方列表中查看所有打開的工作簿。 看截圖:
doc檢查文件是否打開4

這款獨特的敏感免洗唇膜採用 Moisture WrapTM 技術和 Berry Mix ComplexTM 成分, 導航 窗格中,您還可以在列表中的工作簿或工作表之間快速切換。

單擊此處以了解有關導航的更多信息。

最佳辦公生產力工具

🤖 Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行   |  生成代碼  |  建立自訂公式  |  分析數據並產生圖表  |  呼叫 Kutools 函數...
熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


Office選項卡為Office帶來了選項卡式界面,使您的工作更加輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 將您的工作效率提高 50%,每天為您減少數百次鼠標點擊!
Comments (6)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
It doesn't work when the file has macros
This comment was minimized by the moderator on the site
I add this to my code but im having some issues...

I use ur function to check if a workbook with i take some information from is already open or not, if it is open, the macro msgbox the user, telling him to close the workbook and restart the macro, till here, everything ok, the problem is, after closing the workbook and restarting the macro, it keeps saying the workbook is open while its not, any tips?


Code:


Sub Check_BKG()

Set wa = Nothing

Confirmação = MsgBox("Deseja realizar a checagem de dados?", vbYesNo + vbExclamation, "Aviso Macro")
If Confirmação = vbNo Then Exit Sub

'--------------------------------------------------------------------------------------------'
'////////////////////////////CHECANDO SE EXSH JÁ ESTA ABERTO\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
'--------------------------------------------------------------------------------------------'
Dim xRet As Boolean
xRet = IsWorkBookOpen("EXSH0101.xlsx")
If xRet Then
MsgBox "O arquivo EXSH0101 já está aberto, por favor, feche o arquivo antes de executar a macro novamente.", vbInformation, "ERRO EXSH0101"
'MsgBox "The EXSH0101 file is already open, please close it before restart the macro.", vbInformation, "EXSH0101 ERROR"
Exit Sub
End If
'--------------------------------------------------------------------------------------------'
'////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
'--------------------------------------------------------------------------------------------'

With Application
.EnableEvents = False
.ScreenUpdating = False
End With

Call Abrir_Arquivos

Call Setando_EXSH

Call Inserir_Formulas

With Application
.EnableEvents = True
.ScreenUpdating = True
End With

wb.Sheets("Inserir").Activate

End Sub
This comment was minimized by the moderator on the site
Just want to make sure everyone is aware, the "IsWorkBookOpen" function will only be able to tell if a workbook is open in the current instance of Excel. If you have multiple instances open you would need to run it on each instance to be sure the workbook is (not) open, using this code alone.
This comment was minimized by the moderator on the site
Thanks for your reminder.
This comment was minimized by the moderator on the site
Wow, super VBA, simple and works. Thank you very much :)
This comment was minimized by the moderator on the site
Excellent VBA, works great. Thanks.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations