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 29 30 31 32 33 34
|
Private Sub Workbook_Open()
Dim clTemp As Workbook ' classeur temporaire
Dim modClTemp As Object ' le module ThisWorkbook du classeur temporaire
Application.Workbooks.Add ' creer un classeur
Set clTemp = Application.Workbooks(Workbooks.Count) ' definir clTemp
Set modClTemp = clTemp.VBProject.VBComponents("ThisWorkbook") ' definir modClTemp
' ------------------------- Ecrire dans modClTemp ----------------------
With modClTemp.CodeModule
.InsertLines Line:=1, _
String:="Sub Workbook_Open()"
' cl: notre classeur initial
.InsertLines Line:=2, _
String:="set cl = Application.Workbooks(Workbooks.Count - 1)"
.InsertLines Line:=3, _
String:="nomCl = cl.FullName"
.InsertLines Line:=4, _
String:="cl.Close"
.InsertLines Line:=5, _
String:="If ThisWorkbook.Sheets(1).Cells(1, 1).Value = ""moi"" Then"
.InsertLines Line:=6, _
String:="Application.Workbooks.Open Filename:=nomCl, ReadOnly:=False"
.InsertLines Line:=7, _
String:="Else"
.InsertLines Line:=8, _
String:="Application.Workbooks.Open Filename:=nomCl, ReadOnly:=True"
.InsertLines Line:=9, _
String:="End If"
.InsertLines Line:=10, _
String:="end sub"
End With
' ---------------------------------------------------------- |
Partager