'- le projet à exporter ne doit pas être protégé
'- la librairie Microsoft Visual Basic Extensibility 5.x doit être cochée
Sub ExportModules()
Dim fichier As String
Dim f As Integer
Dim i As Integer
Dim oComposant As VBComponent
Dim sNomModule As String, LigneTitre As String
fichier = Replace(ThisWorkbook.FullName, "xls", "txt")
f = FreeFile()
Open fichier For Output As #f
For Each oComposant In ThisWorkbook.VBProject.VBComponents
sNomModule = oComposant.Name
If oComposant.Type = vbext_ct_ClassModule Or vbext_ct_StdModule or vbext_ct_MSForm Then
' 1 ligne vide +3 lignes de titre de module
Print #f, ""
LigneTitre = "'" & String(40, "*")
Print #f, LigneTitre
LigneTitre = String(20, " ") & sNomModule
Print #f, LigneTitre
LigneTitre = "'" & String(40, "*")
Print #f, LigneTitre
' Ecrire les lignes du modules
For i = 1 To oComposant.CodeModule.CountOfLines
Print #f, oComposant.CodeModule.Lines(i, 1)
Next i
End If
Next oComposant
Close #f
End Sub