測試或檢查是否存在工作表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個贊
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
添加回答
舉報
0/150
提交
取消