TestSuite '' '' With TestSuite '' .testAll '' '.testAll ("test") 'procedurePrefix '' '.testAll (procedurePrefix =:"test", modeulePrefix :="テスト") '' End With '' ''End Sub Private Const VBEXT_CT_STDMODULE As Integer = 1 Public Sub testAll(Optional procedurePrefix As String = "", Optional modeulePrefix As String = "test") Dim subProcedureNames As Collection 'Collection<String> Set subProcedureNames = getSubProcedureNames(modeulePrefix) Dim subProcedureName As String Dim v For Each v In subProcedureNames subProcedureName = v If Not isEmpty(procedurePrefix) Then If Not startWith(subProcedureName, procedurePrefix) Then GoTo continue End If End If Application.Run ThisWorkbook.Name & "!" & subProcedureName continue: Next End Sub
As Collection 'Collection<VBComponent> Dim subProcedureNames As New Collection 'Collection<String> Dim VBComponent As Object Set modules = getModules(modeulePrefix) Dim v Dim i Dim subProcedureName As String For Each v In modules Set VBComponent = v With VBComponent.CodeModule For i = 1 To .CountOfLines subProcedureName = .ProcOfLine(i, 0) If isEmpty(subProcedureName) Then GoTo continue End If If contains(subProcedureNames, subProcedureName) Then GoTo continue End If subProcedureNames.add subProcedureName continue: Next i End With Next Set getSubProcedureNames = subProcedureNames End Function
As New Collection Dim VBComponent As Object Dim v For Each v In ThisWorkbook.VBProject.VBComponents Set VBComponent = v With VBComponent If .Type <> VBEXT_CT_STDMODULE Then GoTo continue: End If If Not startWith(.Name, modeulePrefix) Then GoTo continue: End If col.add VBComponent End With continue: Next Set getModules = col End Function Private Function contains(col As Collection, value) As Boolean Dim v For Each v In col If v = value Then contains = True Exit Function End If Next End Function Private Function isEmpty(s As String) As Boolean If s = "" Then isEmpty = True End If End Function Private Function startWith(s As String, prefix As String) As Boolean If InStr(1, s, prefix) = 1 Then startWith = True End If End Function