Excel VBA如果WorkSheet(“wsName”)存在 [英] Excel VBA If WorkSheet("wsName") Exists
本文介绍了Excel VBA如果WorkSheet(“wsName”)存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如果工作簿中的工作表存在,是否有干净的剪切功能返回True或False?
I'm wondering if there is clean cut functionality that returns True or False if a worksheet inside a workbook exists?
如果可以在不跳过错误处理的情况下执行此操作,那将是一件好事,但并不重要。
It would be good, but not essential, if it's possible to do it without skipping error handling.
我发现唯一的事情并不真正有效:
The only thing I've found doesn't really work:
On Error Resume Next
If (Worksheets("wsName").Name <> "") Then
Debug.Print "Worksheet exists!"
Else
Debug.Print "Worksheet doesn't exist!"
End If
On Error GoTo ErrHandler
推荐答案
没有错误处理的版本:
Function sheetExists(sheetToFind As String) As Boolean
sheetExists = False
For Each sheet In Worksheets
If sheetToFind = sheet.name Then
sheetExists = True
Exit Function
End If
Next sheet
End Function
这篇关于Excel VBA如果WorkSheet(“wsName”)存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文