사용자 지정 UI 편집기에서 리본 XML에 콜백 함수를 추가 한 다음 리본 탭이 무효화 될 때 호출 할 VBA 프로젝트에 해당 코드를 추가해야합니다. 드롭 다운 컨트롤에 대해 선택한 항목을 설정하는 데 필요한 콜백은 인덱스 또는 ID로 항목을 선택할지 여부에 따라 getSelectedItemIndex
또는 getSelectedItemID
입니다. 당신이 코드를 제공하지 않았으므로, 내 examle는 일반적으로 (그리고 테스트하지) :
리본 XML :
<dropDown id="drpTest" label="Test dropdown" getSelectedItemIndex="drpTestGetSelectedItem" ></dropDown>
VBA 콜백
'Callback for drpTest getSelectedItemIndex
Sub drpTestGetSelectedItem(control As IRibbonControl, ByRef returnedVal)
returnedVal = 1 '***** To select the item with index 1,
'***** replace with code to select the desired item
End Sub
편집 :
인덱스가 기반으로 선택되는 예제 다른 droplist에. 유사한 솔루션에서 나는 하나의 제어의 onAction
기능에 값을 설정하고, 다른 컨트롤에서 다음과 같이 선택된 인덱스를 설정하는 데 사용했다 :
리본 XML :
<dropDown id="drpTest1" label="Test dropdown 1" onAction="drpTest1OnAction" ></dropDown>
<dropDown id="drpTest2" label="Test dropdown 2" getSelectedItemIndex="drpTest2GetSelectedItem" ></dropDown>
VBA를 콜백
Global myRibbon As IRibbonUI
Global giIndex As Integer
'Callback for customUI.onLoad
Sub RibbonOnLoad(ribbon As IRibbonUI)
'***** Save reference to ribbon object to invalidate
Set myRibbon = ribbon
End Sub
'Callback for drpTest1 onAction
Sub drpTest1OnAction(control As IRibbonControl, id As String, index As Integer)
'***** Set selected item variable for drpTest2
giIndex = index
'***** Tell Excel to redraw ribbon
'(you could invalidate only parts of the ribbon with InvalidateControl
'or InvalidateControlMso)
myRibbon.Invalidate
End Sub
'Callback for drpTest2 getSelectedItemIndex
Sub drpTest2GetSelectedItem(control As IRibbonControl, ByRef returnedVal)
'***** Return selected item for drpTest2 based on value stored in giIndex
returnedVal = giIndex
End Sub
이러한 데이터 유효성 검사 드롭 다운 목록 또는 activeX 콤보 상자가 있습니까? 혼동이 없도록 일부 코드를 게시해야합니다. – Amorpheuses
@Amorpheuses Excel의 리본에 추가 된 DropDown 컨트롤입니다. 이 개체입니다 : https://msdn.microsoft.com/en-us/library/dd947478(v=office.12).aspx –