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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
| Option Explicit
' Sous VBE Menu Outils/Références cocher Microsoft Forms 2.0 Object Library
' sinon parcourir et sélectionner c:\windows\system32\FM20.dll
Sub Création()
Dim UsfForm As Object
Dim NewB As MSForms.CommandButton
Dim TxtB As MSForms.TextBox
Dim i As Long, j As Long
Dim UsfName As String
Dim iLeft As Long, iTop As Long
ShTest.Cells.Clear
Application.VBE.MainWindow.Visible = False
Set UsfForm = ThisWorkbook.VBProject.VBComponents.Add(3)
With UsfForm
.Properties("Caption") = "USF et TextBoxes Dynamiques"
.Properties("Width") = 175
.Properties("Height") = 375
End With
UsfName = UsfForm.Name
Set NewB = UsfForm.Designer.Controls.Add("Forms.CommandButton.1")
With NewB
.Height = 28
.Width = 70
.Left = 50
.Top = 315
.Caption = "Quitter"
End With
iLeft = 10: iTop = 10
For i = 1 To 12
Set TxtB = UsfForm.Designer.Controls.Add("Forms.Textbox.1", , True)
With TxtB
.Width = 150
.Height = 20
.Left = iLeft
.Top = iTop
.BorderStyle = fmBorderStyleSingle
.SpecialEffect = fmSpecialEffectFlat
Select Case i
Case 1, 5
.BackColor = &HC0E0FF
Case Else
.BackColor = &HC0FFFF
End Select
.Tag = i
End With
iTop = iTop + 25
Next i
With UsfForm.CodeModule
i = .CountOfLines
If i = 2 Then
.InsertLines i, "": i = i + 1
Else
i = 1
End If
.InsertLines i, "Const entrees_decimales_permises = "",0123456789": i = i + 1
.InsertLines i, "Const entrees_alpha_permises = "" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz": i = i + 1
.InsertLines i, "Const Point = "".": i = i + 1
.InsertLines i, "Const Virgule = "",": i = i + 1
.InsertLines i, "": i = i + 1
.InsertLines i, "Private Sub CommandButton1_Click()": i = i + 1
.InsertLines i, " Unload Me": i = i + 1
.InsertLines i, "End Sub": i = i + 1
For j = 1 To 12
.InsertLines i, "": i = i + 1
.InsertLines i, "Private Sub TextBox" & j & "_Change()": i = i + 1
.InsertLines i, "Dim i As Integer": i = i + 1
.InsertLines i, " i = TextBox" & j & ".Tag": i = i + 1
.InsertLines i, " Select Case i": i = i + 1
.InsertLines i, " Case 1, 5": i = i + 1
.InsertLines i, " ShTest.Range(""A" & j & Chr(34) & ")=TextBox" & j & ".Text": i = i + 1
.InsertLines i, " Case Else": i = i + 1
.InsertLines i, " On Error Resume Next": i = i + 1
.InsertLines i, " ShTest.Range(""A" & j & Chr(34) & ")=CDbl(" & "TextBox" & j & ".Text)": i = i + 1
.InsertLines i, " Err.Clear": i = i + 1
.InsertLines i, " End Select": i = i + 1
.InsertLines i, "End Sub": i = i + 1
.InsertLines i, "": i = i + 1
.InsertLines i, "Private Sub TextBox" & j & "_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)": i = i + 1
.InsertLines i, " Select Case TextBox" & j & ".Tag": i = i + 1
.InsertLines i, " Case 1, 5": i = i + 1
.InsertLines i, " If InStr(entrees_alpha_permises, Chr(KeyAscii)) = 0 Then KeyAscii = 0": i = i + 1
.InsertLines i, " Case Else": i = i + 1
.InsertLines i, " If KeyAscii = Asc(Point) Then": i = i + 1
.InsertLines i, " If InStr(TextBox" & j & ".Text, Virgule) = 0 Then": i = i + 1
.InsertLines i, " KeyAscii = Asc(Virgule)": i = i + 1
.InsertLines i, " Else": i = i + 1
.InsertLines i, " KeyAscii = 0": i = i + 1
.InsertLines i, " End If": i = i + 1
.InsertLines i, " ElseIf InStr(entrees_decimales_permises, Chr(KeyAscii)) = 0 Then": i = i + 1
.InsertLines i, " KeyAscii = 0": i = i + 1
.InsertLines i, " ElseIf InStr(TextBox" & j & ".Text, Virgule) > 0 And KeyAscii = Asc(Virgule) Then": i = i + 1
.InsertLines i, " KeyAscii = 0": i = i + 1
.InsertLines i, " End If": i = i + 1
.InsertLines i, " End Select": i = i + 1
.InsertLines i, "End Sub": i = i + 1
Next j
.InsertLines i, "": i = i + 1
.InsertLines i, "Private Sub UserForm_Initialize()": i = i + 1
.InsertLines i, " TextBox1.setfocus": i = i + 1
.InsertLines i, "End Sub": i = i + 1
End With
VBA.UserForms.Add(UsfName).Show
ThisWorkbook.VBProject.VBComponents.Remove VBComponent:=UsfForm
End Sub |
Partager