2010-03-03 2 views
9

일반 VBA 양식 컨트롤 개체를 ComboBox 개체로 캐스팅해야 항목을 추가 할 수 있습니다. 일반 객체는 나를Excel VBA : 일반 컨트롤 개체를 ComboBox 개체로 캐스팅하는 방법?

Dim ctlCurrent As MSForms.Control 
For Each ctlCurrent In frmItemInput.Controls 
    If TypeName(ctlCurrent) = "ComboBox" Then 
     Dim lbCurrentComboBox As MSForms.ComboBox 
     lbCurrentComboBox = ctlCurrent 'This is where the error occurs, when I try to convert one into another 

     ' Adiciona os itens necessários 
     lbCurrentComboBox.AddItem ("R") 
     lbCurrentComboBox.AddItem ("D") 
    End If 
Next ctlCurrent 

내 문제는 내 기존 목록에 항목을 삽입 할 수 없습니다 : 내 형태로 선택 상자의 톤을 가지고 있고 그들 모두에 대해 동일한 옵션을 추가해야합니다. 그래서 저는 이것을 progrmatically하고 싶습니다.

+1

졸개을 시도 작동하지 않았다 마우스 오른쪽 있습니다. 세트를 사용해야합니다. – Stewbob

답변

14

당신은 예를 들어, SET를 사용하여 VBA 개체 "캐스트"할 수 있습니다

SET lbCurrentComboBox = ctlCurrent 
+2

안녕하세요, 감사합니다! 이것은 트릭을했다. –

+1

내가 필요한 것. –

5

phil's answer 경우가

SET lbCurrentComboBox = ctlCurrent.Object