VBAでモジュールをエクスポートする

  • code
    Public Sub exportModule()
    
      Dim targetModule As VBComponent, outputPath As String
    
      outputPath = ActiveWorkbook.Path & "/src/"
      For Each targetModule In ActiveWorkbook.VBProject.VBComponents
    
          If targetModule.CodeModule.CountOfLines > 3 Then
              If targetModule.Type = vbext_ct_StdModule Then
                  targetModule.Export outputPath & targetModule.Name & ".bas"
              End If
    
              If targetModule.Type = vbext_ct_ClassModule Then
                  targetModule.Export outputPath & targetModule.Name & ".cls"
              End If
          End If
      Next
    
    End Sub