RibbonX-Workshop - Kombinationsfeld
Erstellen Sie eine neue Arbeitsmappe. Fügen Sie ein neues Modul und in dieses die folgenden für das Kombinationsfeld gültigen Makros ein.
Option Explicit
Public objRibbon As IRibbonUI
Rem Callback for customUI.onLoad
Public Sub rx_onLoad(ribbon As IRibbonUI)
Set objRibbon = ribbon
End Sub
Rem Sub wird beim ersten Anklicken des Pfeils der ComboBox
Rem und dann bei jeder Neuinitialisierung ausgeführt
Rem Callback for cboCombo getItemCount
Public Sub cboCombo_getItemCount(control As IRibbonControl, ByRef returnedVal)
Rem Anzahl Einträge festlegen (Monate)
returnedVal = 12
End Sub
Rem Sub wird nach Wert der Variable returnedVal aus getItemCount
Rem n mal durchlaufen
Public Sub cboCombo_getItemID(control As IRibbonControl, index As Integer, ByRef id)
Rem Eindeutiger Index je Eintrag festlegen
id = "Month" & index
End Sub
Rem Callback for cboCombo getItemLabel
Public Sub cboCombo_getItemLabel(control As IRibbonControl, index As Integer, ByRef returnedVal)
Rem Beschriftung je Eintrag festlegen
returnedVal = MonthName(index + 1)
End Sub
Rem Callback für cboCombo onChange
Public Sub cboCombo_onChange(control As IRibbonControl, text As String)
Rem Auswahl aus Kombinationsfeld in aktive Zelle schreiben
ActiveCell.Value = text
End Sub
Speichern Sie nun die Änderung und schließen die Arbeitsmappe. Öffnen Sie selbige mit dem CustomUI-Editor und fügen in das Codefenster folgenden Code ein.
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="rx_onLoad">
<ribbon>
<tabs>
<!--Benutzerdefinierte Registerkarte am Anfang erstellen-->
<tab id="tb1" label="Combobox" insertBeforeMso="TabHome">
<group id="grpCombo" label="Combobox">
<comboBox id="cboCombo" label="Monate:" screentip= "Dynamisches Kombinationsfeld"
supertip="Die Auswahl eines Eintrages wird in die aktive Zelle geschrieben"
onChange="cboCombo_onChange" getItemCount="cboCombo_getItemCount"
getItemID="cboCombo_getItemID" getItemLabel="cboCombo_getItemLabel">
</comboBox>
</group>
</tab>
</tabs>
</ribbon>
</customUI>