为了账号安全,请及时绑定邮箱和手机立即绑定

测试或检查是否存在工作表

测试或检查是否存在工作表

测试或检查是否存在工作表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 关注
  • 800 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信