当我将数组值作为字符串传递时,这两个函数都不起作用。
生成错误:编译错误:ByRef参数类型不匹配
If SheetExists(StruArr(R, 2)) Then Sheets(StruArr(R, 2)).Delete
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)
SheetExists = True
Exit Function
HandleError:
SheetExists = False
End Function
Function ChkWs(ws As String) As Boolean
Dim ws As Worksheet
Dim ret As Boolean
ret = False
wsName = UCase(wsName)
For Each ws In ThisWorkbook.Sheets
If UCase(ws.Name) = wsName Then
ret = True
Exit For
End If
Next
ChkWs = ret
End Function
如果我使用直接文本,例如
If SheetExists("abcd") Then Sheets("abcd").Delete
它会完美运作。