つらつら Excel VBA

私の備忘録です。

ユーザーフォームを数える

'指定した名前のユーザーフォームを数える
Function countUserForm(name As String) As Integer
    Dim cnt As Integer
    Dim frm As Object
    cnt = 0
    For Each frm In UserForms
        If UCase(frm.Caption) = UCase(name) Then
            cnt = cnt + 1
        End If
    Next
    countUserForm = cnt
End Function

※UCase  アルファベットの小文字を大文字に変換する。
(LCaseは逆の動作)
文字の大小が区別されるので、どちらかに統一して比較する。