Sub シートの存在確認()
Dim ws As Worksheet
Dim flag As Boolean
For Each ws In Worksheets
If ws.Name = "〇〇" Then
flag = True
End If
Next ws
If flag Then
MsgBox "「〇〇」シートあり"
Else
MsgBox "「〇〇」シートなし"
End If
End Sub
' シート存在確認
Public Function ExistsSheet( _
ByVal sheetName As String, _
Optional ByVal wb As Workbook = Nothing _
) As Boolean
Dim ws As Worksheet
If wb Is Nothing Then Set wb = ThisWorkbook
For Each ws In wb.Worksheets
If StrComp(ws.Name, sheetName, vbTextCompare) = 0 Then
ExistsSheet = True
Exit Function
End If
Next
ExistsSheet = False
End Function
コメント