2017-09-12 5 views
2

この質問は、私が取り組んでいるプロジェクトの「パート3」です。 adding multiple labels and textboxes to an Excel userform during runtime using vbaretrieving data from multiple textboxes created during runtime in an Excel userform using vbaの後、私は今、すべてのデータを使用して、ドロップダウンボックスの名前を選択して作業を割り当てようとしています。複数のドロップダウンボックスをVBAを使用してExcel UserFormでオプションを指定して選択する

enter image description here

私がいる問題は、私はそれがこれを行うよう、それはまたをループされ、私たちの従業員の名前を与えるUBoundLBoundからMyArray(i)をループに設定したコードを持っている、ですUserFormから取得したMultFLNAmtを分割して作成した配列で、各従業員が受け取るFLNの数を決定することができます。割り当てられた現在の従業員の名前を見つけるためにループします。すべての作業が完了し、誰もが正しい量のFLNが割り当てられたら、アプリケーションの[Submit]ボタンをクリックして割り当てを完了します。

' Shows and hides the multiple option UserForm 
MultipleOptionForm.Show 

MultipleOptionForm.Hide 

' Creates an array from a comma-delimited 
' list of numbers stored in a variable 
MFA = Split(MultFLNAmt, ",") 

' Activates the application we will be assigning work from 
WShell.AppActivate "Non-Keyable Document Management System" 

' Table cell node where the dropdown is located 
tdNode = 64 
a = 1 

' Loop through each of the names within the array 
For c = LBound(MyArray) + 1 To UBound(MyArray) - 1 
    ' Loop through the array to see how many FLNs each person receives 
    For b = 1 To MFA(a) 
     ' Loop through to locate the current name of the employee 
     i = 0 
     For Each objOption In objIE.Document.GetElementsByTagName("table")(0).GetElementsByTagName("td")(tdNode).GetElementsByClassName("txt_input1")(0).Options 
      Q(i) = objOption.Text & "-" & objOption.Value 

      strWQ = Q(i) 
      ' Remove "Selected User" from the list of options 
      If i = 0 Then 
       If strWQ = "--Select User---" Then strWQ = "" 
      Else 
       ' If an option matches the current name selected, 
       ' select that option, then increase the node location 
       ' for the next dropdown box 
       If InStr(strWQ, MyArray(c)) Then 
        objOption.Selected = True 
        objIE.Document.GetElementsByTagName("table")(0).GetElementsByTagName("td")(tdNode).GetElementsByClassName("txt_input1")(0).OnChange 
        tdNode = tdNode + 23 
       Else 
        objOption.Selected = False 
       End If 
      End If 
     Next    
     i = i + 1    
    Next 
Next 

objIE.Document.all.Item("btn_submit1").Click 

コードはそれが失敗の最も部分、のために働いている間MFA(a)が2以上の場合、最初のドロップダウンを選択します。私はデバッグモードでコードを入れて、なぜ2つ以上が選択されていないのか見ていません。何か案は?

答えて

0

多くの研究の末、私は最終的に自分のプロジェクトをどのように動かすかを考え出しました。

' This line allows for growth/shrinkage of the list of employees 
MultipleOptionForm.Height = (UBound(MyArray) - 1) * 20 

' This line shows the form 
MultipleOptionForm.Show 

' This line hides the form after being updated 
MultipleOptionForm.Hide 

' Creates an array from a comma-delimited 
' list of numbers stored in a variable 
MFA = Split(MultFLNAmt, ",") 

' Activates the application we will be assigning work from 
WShell.AppActivate "Non-Keyable Document Management System" 

' Table cell node where the dropdown is located 
tdNode = 64 
' MFA index 
a = 1 

' Loop through each of the names within the array 
For c = LBound(MyArray) + 1 To UBound(MyArray) - 1 
    ' Loop through the array to see how many FLNs each person receives 
    For b = 1 To MFA(a) 
     ' Starts loop at first drop down 
     On Error Resume Next 
      For Each objOption In objIE.Document.GetElementsByTagName("table")(0).GetElementsByTagName("td")(tdNode).GetElementsByClassName("txt_input1")(0).Options 
       ' Stores options within drop down 
       strWQ = objOption.Text & "-" & objOption.Value 
       If IsEmpty(strWQ) Then 
        Exit Sub 
       End If 
       ' Remove "Selected User" from the list of options 
       If strWQ = "--Select User---" Then 
        strWQ = "" 
       Else 
        ' If there's a match between the drop down for the list 
        ' and the list of assigned FLNs, begin assigning 
        If InStr(strWQ, MyArray(c)) Then 
         objOption.Selected = True 
         objIE.Document.GetElementsByTagName("table")(0).GetElementsByTagName("td")(tdNode).GetElementsByClassName("txt_input1")(0).OnChange 
         tdNode = tdNode + 23 
         Exit For 
        Else 
         objOption.Selected = False 
        End If 
       End If 
      Next 
     On Error GoTo 0 
    Next 
Next 
関連する問題