1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| Sub creationModule()
'Nécéssite d'activer la référence
'"Visual basic For Application Extensibility 5.3"
'
Dim Wb As Workbooks
Dim VBComp As VBComponent
Dim X As Integer
'Définit le classeur cible
Set Wb = Workbooks((Stock_var.chemin_nom.Text) & "\" & (affaire))
'Stock_var.chemin_nom.Text correspond a l emplacement du fichier
'affaire correspond au nom du fichier
'Ajoute un module standard dans le classeur
'.VBProject.VBComponents
Set VBComp = Wb.Add(1)
'Renomme le module
VBComp.name = "NouveauModule"
'Ajoute une macro dans le module
With VBComp.CodeModule
X = .CountOfLines
.InsertLines X + 1, "Sub laMacro()"
.InsertLines X + 2, "Columns(""I:J"").Select"
.InsertLines X + 3, "Selection.Sort Key1:=Range(""I1""), Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal"
.InsertLines X + 4, "End Sub"
End With
End Sub |
Partager