如何设置userform对象以在窗体(VBA)中设置文本框值

时间:2013-10-28 07:15:23

标签: excel vba excel-vba

Public Function GetProfileDetails(FormID As String,ControlName As String ,ProfileName As String)
    'Dim FormName As String: FormName = GetUserFormName(FormID)
    Dim ProfileRange As range: Set ProfileRange = range("DYUI_Profile")
    Dim TempRange As range: Set TempRange = Nothing
    Dim i As Integer: i = 0
    Dim ProfileColIndex As Integer: ProfileColIndex = getColumnIndex("Profile", ProfileRange)
    Dim UserNameColIndex As Integer: UserNameColIndex = getColumnIndex("UserName", ProfileRange)
    Dim PassowrdColindex As Integer: PassowrdColindex = getColumnIndex("Password", ProfileRange)
    Dim URLColIndex As Integer: URLColIndex = getColumnIndex("URL", ProfileRange)
    Dim RowCnt As Integer: RowCnt = ProfileRange.rows.Count

    For i = 2 To RowCnt
        If Trim(UCase(ProfileRange.rows.Cells(i, ProfileColIndex))) = Trim(UCase(ProfileName)) Then
            If TempRange Is Nothing Then
                Set TempRange = ProfileRange.rows(i)
            Else
                Set TempRange = Application.Union(TempRange, ProfileRange.rows(i))
            End If
        End If
    Next i

    For i = 1 To TempRange.rows.Count
        FormName.ControlName.Text = TempRange.rows.Cells(i, UserNameColIndex).Value
        FormName.ControlName.Text = TempRange.rows.Cells(i, PassowrdColindex).Value
        FormName.ControlName.Text = TempRange.rows.Cells(i, URLColIndex).Value
    Next i

    Worksheets("Form_Output").Cells(1, 3).Value = FormName.ControlName.Value
    Worksheets("Form_Output").Cells(1, 5).Value = FormName.ControlName.Value
    Worksheets("Form_Output").Cells(1, 7).Value = FormName.ControlName.Value   
End Function

1 个答案:

答案 0 :(得分:0)

您不能像这样使用字符串表单或控件名称。传递您要使用的控件对象:

Public Function GetProfileDetails(TextBox As TextBox, ProfileName As String)