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
| Sub refaire_macro()
Dim Wb As Workbook
Dim VBComp As VBComponent
Dim X As Integer
'Définit le classeur cible
Set Wb = Workbooks("book1.xlsm")
'Définir ou on va mettre le code
Set VBComp = Wb.VBProject.VBComponents("ThisWorkbook")
'Ajoute une macro dedans
With VBComp.CodeModule
X = .CountOfLines
.InsertLines X + 1, "Option Explicit"
.InsertLines X + 2, "Dim i As Integer"
.InsertLines X + 3, "Private Sub Workbook_Open()"
.InsertLines X + 4, "For i = 1 To 12"
.InsertLines X + 5, " If Sheets(i).Cells(1, 11) = ""non"" Then"
.InsertLines X + 6, " Sheets(i).Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, userInterfaceOnly:=True"
.InsertLines X + 7, " Sheets(i).EnableOutlining = True"
.InsertLines X + 8, " End If"
.InsertLines X + 9, "Next i"
.InsertLines X + 10, "End Sub"
End With
End Sub |
Partager