2013-10-28 65 views
0
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 

回答

0

您不能像這樣使用字符串窗體或控件名稱。傳遞您要使用的控制對象:

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

嗨博南......它是在窗體名稱一樣無效預選賽... –

+0

給錯誤@ milan.s替換所有'FormName.ControlName.'用'文本框.'。 – Boann

+0

但我動態生成表單,所以我需要用戶名錶單或引用來引用表單的控制... –