亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

測試或檢查是否存在工作表

測試或檢查是否存在工作表

測試或檢查是否存在工作表Dim wkbkdestination As WorkbookDim destsheet As WorksheetFor Each ThisWorkSheet In wkbkorigin.Worksheets      'this throws subscript out of range if there is not a sheet in the destination      'workbook that has the same name as the current sheet in the origin workbook.     Set destsheet = wkbkdestination.Worksheets(ThisWorkSheet.Name) Next基本上,我循環遍歷原始工作簿中的所有工作表,然后設置destsheet在目標工作簿中,指向與原版工作簿中當前迭代的工作表名稱相同的工作表。我怎樣才能測試那張紙是否存在?類似于:If wkbkdestination.Worksheets(ThisWorkSheet.Name) Then
查看完整描述

3 回答

?
Cats萌萌

TA貢獻1805條經驗 獲得超9個贊

有些人不喜歡這種方法,因為錯誤處理的使用“不適當”,但我認為它在VBA中是可以接受的.另一種方法是循環遍歷所有的工作表,直到找到匹配的頁為止。

Function WorksheetExists(shtName As String, Optional wb As Workbook) As Boolean
    Dim sht As Worksheet    If wb Is Nothing Then Set wb = ThisWorkbook    On Error Resume Next
    Set sht = wb.Sheets(shtName)
    On Error GoTo 0
    WorksheetExists = Not sht Is NothingEnd Function


查看完整回答
反對 回復 2019-06-18
  • 3 回答
  • 0 關注
  • 871 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號