Public Function SheetExists(strSheetName As String, Optional wbWorkbook As Workbook) As Boolean If wbWorkbook Is Nothing Then Set wbWorkbook = ActiveWorkbook 'or ThisWorkbook - whichever appropriate Dim obj As Object On Error GoTo HandleError Set obj = wbWorkbook.Sheets(strSheetName) Sheet...
Function SheetExists(SheetName As String, Optional wb As Excel.Workbook) Dim s As Excel.Worksheet If wb Is Nothing Then Set wb = ThisWorkbook On Error Resume Next Set s = wb.Sheets(SheetName) On Error GoTo 0 SheetExists = Not s Is Nothing End Function Share Improve this answer Follow ...
PathExists:检查路径是否存在 –Returns TRUE if a particular path exists. RangeNameExists:区域名称是否已存在 –Returns TRUE if a particular range name exists. SheetExists:检查工作表是否存在 –Returns TRUE if a particular sheet exists. WorkBookIsOpen:检查工作簿是否打开 –Returns TRUE if a particular ...
Exit Function End If Next IsSheetExisted = False End Function 我们将函数名随便起了个名字叫IsSheetExisted,函数只有一个字符串型参数tabname代表以后要传入的工作表标签名称,函数返回Boolean类型结果(True/False)。下面,我们就可以在其它VBA程序中使用该函数了,见下面代码: Sub 判断工作表是否存在() MsgBox IIf(...
Sub Test() Dim sheetName As String sheetName = "Sheet1" If WorksheetExists(sheetName) Then MsgBox "工作表已存在!" Else MsgBox "工作表不存在!" End If End Sub 在上述示例中,我们将要检查的工作表名称传递给WorksheetExists函数,并根据返回的结果显示相应的消息框。 腾讯云提供了一系列与Excel相关的产品...
If d.exists("东门子订单数据") Then MsgBox "存在" Else MsgBox "不存在" End If End Sub 第3种方法: 巧妙运用On Error...错误语句方法来判断是否存在。 Sub 判断工作表是否存在_方法3() Dim sht As Worksheet On Error Resume Next Set sht = Worksheets("东门子订单数据") ...
() Dim numberSheetID As Integer = 1 Dim strSheetName As String = Nothing Dim SheetCount As Integer = 0 If Not System.IO.File.Exists(filepath) Then MsgBox("This file is not exist") End If Try Dim obj As Microsoft.Office.Interop.Excel.Application = Nothing Dim objWB As Microsoft....
NewSheetName = SourceSheet.Name If SheetExists(TargetWorkbook, NewSheetName) Then '如果...
End If End Sub 没有错误处理的版本: 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 没有内置功能。
"))If tRow = 0 Then MsgBox "您未输入标题行行数,程序退出!": Exit SubSet Rng = ActiveSheet.UsedRangearr = RngtCol = tCol - Rng.Column + 1aCol = UBound(arr, 2)For i = tRow + 1 To UBound(arr)If Not d.exists(arr(i, tCol)) Thend(arr(i, tCol)) = iElsed(arr(i, tCol)...