在Excel VBA中,如何判断一个名为'abc'的 sheet是否存在? ( 积分: 100 )

  • 主题发起人 主题发起人 duke2000
  • 开始时间 开始时间
自己回答吧,请指教,还有高招没有?VBA这么弱,连个判断函数都没有?!
自定义函数:
Function WorkSheetExists(wb As Workbook, sName As String) As Boolean
Dim s As String

On Error GoTo bWorkSheetExistsErr

s = wb.Sheets(sName).Name

WorkSheetExists = True
Exit Function

bWorkSheetExistsErr:
WorkSheetExists = False
End Function
 
这有个正统一点的:
Function WorkSheetExists(wb As Workbook, sName As String) As Boolean
Dim intloop As Integer
WorkSheetExists = False
For intloop = 1 To wb.Sheets.Count
If wb.Sheets(intloop).Name = sName then
WorkSheetExists = True
Exit Function
End If
Next intloop
End Function
 
VBA其实很多东西跟VB是一样的,我现在也在研究这个东西,有空可以多交流下
QQ:99128682
 
后退
顶部