Вы находитесь на странице: 1из 3

Sub RunMainForm() Dim Dim Dim Dim TempForm As Object NewButton As MSForms.CommandButton NewLabel As MSForms.Label NewTextBox As MSForms.

TextBox

Dim Line As Integer Dim Counter As Integer Dim VariableName As String Dim propertyvalue As String Dim propertycaption As String Dim TopDistance As Integer Dim ActionCommand As String Dim Dim Dim Dim Dim InputFields As String SubInput As String index As Integer indexVal As Integer indexVariable As Integer

InputFields = "{0}" If (Len(InputFields) = 0) = True Then Exit Sub End If index = InStr(InputFields, ";") 'This is to stop screen flashing while creating form Application.VBE.MainWindow.Visible = False Set TempForm = ThisWorkbook.VBProject.VBComponents.Add(3) Do While (index = 0) = False ' Loop until end of file. SubInput = Mid(InputFields, 1, index - 1) indexVariable = InStr(SubInput, "~") indexVal = InStr(SubInput, ":") VariableName = Mid(SubInput, 1, indexVariable - 1) propertyvalue = Mid(SubInput, indexVal + 1) propertycaption = Mid(SubInput, indexVariable + 1, indexVal - (indexVariable + 1)) VariableName = Replace(VariableName, " ", "") TopDistance = 20 + (19 * Counter) 'Create "Column containing Row Type" Label********************************** ************** Set NewLabel = TempForm.Designer.Controls.Add("Forms.label.1") With NewLabel .Name = "lbl" & VariableName .Caption = propertycaption & ":" .Top = TopDistance .Left = 20

.Width = 150 .Height = 18 .Font.Size = 8 .Font.Name = "Tahoma" .Font.Bold = True End With 'Create "Column containing Row Type" TextBox Set NewTextBox = TempForm.Designer.Controls.Add("Forms.textbox.1") With NewTextBox .Name = "txt" & VariableName .Top = TopDistance .Left = 180 .Width = 150 .Height = 18 .Font.Size = 8 .Font.Name = "Tahoma" .Font.Bold = False .Value = propertyvalue End With ActionCommand = ActionCommand & VariableName & " = .txt" & VariableName & ".value" & ": " Counter = Counter + 1 InputFields = Mid(InputFields, index + 1) index = InStr(InputFields, ";") Loop TopDistance = 20 + (22 * Counter) 'Create Command Button controls ******************************************** ********************* Set NewButton = TempForm.Designer.Controls.Add("Forms.CommandButton.1") With NewButton .Name = "btnOk" .Caption = "Ok" .Top = TopDistance .Left = 110 .Width = 70 .Height = 20 .Font.Size = 9 .Font.Name = "Tahoma" End With Set NewButton = TempForm.Designer.Controls.Add("Forms.CommandButton.1") With NewButton .Name = "btnCancel" .Caption = "Cancel" .Top = TopDistance .Left = 200 .Width = 70 .Height = 20 .Font.Size = 9 .Font.Name = "Tahoma" End With

'End Command Button creation************************************************ ************************* 'Event Handlers for Command Button****************************************** *88 With TempForm.codemodule Line = .countoflines '*** For ok button**** .insertLines Line + 1, .insertLines Line + 2, .insertLines Line + 3, .insertLines Line + 4, .insertLines Line + 5, .insertLines Line + 6, .insertLines Line + 7, .insertLines Line + 8,

"Sub btnOk_Click()" "With Me" ".Hide" ActionCommand "{1}" "End With" "Unload Me" "End Sub"

'*** For cancel button**** .insertLines Line + 20, "Sub btnCancel_Click()" .insertLines Line + 21, "With Me" .insertLines Line + 22, ".Hide" .insertLines Line + 23, "End With" .insertLines Line + 24, "Unload Me" .insertLines Line + 25, "End Sub" End With 'Create the Main Form******************************************************8 8 With TempForm .Properties("Caption") = "Document Splitting" .Properties("Width") = 360 .Properties("Height") = TopDistance + 60 End With 'Show the form VBA.UserForms.Add(TempForm.Name).Show 'Delete the form ThisWorkbook.VBProject.VBComponents.Remove TempForm End Sub

Вам также может понравиться