本文介绍了如果 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

这篇关于如果 WorkSheet("wsName") 存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 05:19