[英]How to list all sheets in opened Workbook in Workbook_Open event handler Sub?
當用戶打開保存的工作簿時,我想從其中的隱藏工作表加載數據。
我以為我會使用Workbook_Open
Sub並從該Sub加載該工作表中的數據,但是隨后又調用了此Sub,我還沒有任何Workbook。
這是一個例子:
Private Sub Workbook_Open()
Debug.Print "Open: " & Workbooks.Count 'prints 0 to console
End Sub
我也嘗試過這種方法:
Private Sub Workbook_Open()
Dim sh As Worksheet
For Each sh In Sheets
Debug.Print sh.name
'prints only Sheet1, Sheet2, Sheet3 and do not print the name of my data sheet.
Next sh
End Sub
所以我的問題是:當用戶打開工作簿時,如何按名稱獲取工作表?
我認為您只是缺少一些參考。
我剛剛測試了一下,並且工作得很好:
Private Sub Workbook_Open()
Debug.Print "Opened wB: " & Application.Workbooks.Count
Dim wS As Worksheet
Debug.Print "Sheets: "
For Each wS In ThisWorkbook.Sheets
Debug.Print wS.Name
Next wS
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.