EXCEl 怎样用VBA查找某个表是否存在?

2024-12-21 03:22:01
推荐回答(2个)
回答1:

遍历for each 来比对也是可以的
或则
Sub iexist()
On Error Resume Next
If Sheets(sname) Is Nothing Then
MsgBox "工作表不存在"
Else
MsgBox "工作表存在"
End If
End Sub

回答2:

sName = Worksheets("sheet2").Cells(1, n).Value
for i=1 to ThisWorkbook.Worksheets.count
if ThisWorkbook.Worksheets(i).name=sname then exit for
next
If i>ThisWorkbook.Worksheets.count Then'不存在