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 35 36
| Private Sub CommandButton1_Click()
Dim W As Workbook
Dim vbM As VBComponent
Set W = Workbooks("wanao.xls") 'prend le classeur courant
'crée un nouveau module dans le classeur
Set vbM = W.VBProject.VBComponents.Add(vbext_ct_StdModule)
If TextBox1.Value = 1 Then
'ajoute la fonction qui crée la colonne dans le classeur actif avec 1 col
vbM.CodeModule.InsertLines 1, "Sub colonne"
vbM.CodeModule.InsertLines 2, "Range(""B5"").Select"
vbM.CodeModule.InsertLines 3, "Selection.Borders(xlDiagonalDown).LineStyle = xlNone"
vbM.CodeModule.InsertLines 4, "Selection.Borders(xlDiagonalUp).LineStyle = xlNone"
vbM.CodeModule.InsertLines 5, "With Selection.Borders(xlEdgeLeft)"
vbM.CodeModule.InsertLines 6, ".LineStyle = xlContinuous"
vbM.CodeModule.InsertLines 7, ".Weight = xlThin"
vbM.CodeModule.InsertLines 8, ".ColorIndex = xlAutomatic"
vbM.CodeModule.InsertLines 9, "End With"
vbM.CodeModule.InsertLines 10, "With Selection.Borders(xlEdgeTop)"
vbM.CodeModule.InsertLines 11, ".LineStyle = xlContinuous"
vbM.CodeModule.InsertLines 12, ".Weight = xlThin"
vbM.CodeModule.InsertLines 13, ".ColorIndex = xlAutomatic"
vbM.CodeModule.InsertLines 14, "End With"
vbM.CodeModule.InsertLines 15, "Selection.Borders(xlEdgeBottom).LineStyle = xlNone"
vbM.CodeModule.InsertLines 16, "With Selection.Borders(xlEdgeRight)"
vbM.CodeModule.InsertLines 17, ".LineStyle = xlContinuous"
vbM.CodeModule.InsertLines 18, ".Weight = xlThin"
vbM.CodeModule.InsertLines 19, ".ColorIndex = xlAutomatic"
vbM.CodeModule.InsertLines 20, "End With"
vbM.CodeModule.InsertLines 21, "End sub"
Application.VBE.MainWindow.Visible = False
End If
End Sub |
Partager