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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| Option Explicit
Dim usf As Object
Sub Start_Procedure()
Dim X As Object
Dim i As Integer
Dim strCdeBut As String
strCdeBut = "CommandButton1"
Set X = creation_usf(strCdeBut)
X.Show
ThisWorkbook.VBProject.VBComponents.Remove usf
Set usf = Nothing
End Sub
Function creation_usf(nomBouton As String) As Object
Dim ObjCommandButton As Object
Dim ws As Worksheet, j As Integer
'Set ws = Worksheets("Config")
' Création du UserForm
Set usf = ThisWorkbook.VBProject.VBComponents.Add(3)
With usf
.Properties("Width") = Parent.Width * 0.98
.Properties("Height") = Parent.Height * 0.98
End With
Set ObjCommandButton = usf.Designer.Controls.Add("Forms.CommandButton.1")
With ObjCommandButton
.Name = "AddChrono"
.Caption = "Ajouter au chrono"
.Width = Parent.Width * 0.98 * 0.5
.Top = 1 ' Parent.Height * 0.98 * 0.9
.Left = Parent.Width * 0.98 - .Width - 5
.Height = 18
End With
With usf.CodeModule
' Initialize
.CreateEventProc "Initialize", "UserForm"
j = .ProcStartLine("Userform_Initialize", 0)
.InsertLines j + 2, " dHeight = Me.Height * 0.98"
' AddChrono
.CreateEventProc "Click", "AddChrono"
j = .ProcStartLine("AddChrono_Click", 0)
.InsertLines j + 2, " dim msg as variant" & vbCrLf & _
" msg = inputbox(""Info à ajouter au chrono :"" ,""Inputbox Perso"") " & vbCrLf & _
" if msg <> """" then " & vbCrLf & _
" call logEtat(""'** INFO **"",cstr(msg)) " & vbCrLf & _
" end if"
End With
VBA.UserForms.Add (usf.Name)
Set creation_usf = UserForms(UserForms.Count - 1)
End Function |
Partager