测试或检查是否存在工作表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
提交
取消