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

推荐答案

一个没有错误处理的版本:

A version without error-handling:

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