R
Renate
Hi all,
I hope this is the appropriate group for this question. I didn't now exactly
where to post this.
I am working my way throught the RibbonX book but get stranded on the
chapter of dynamically filled comboboxes.
In the book there's only an example of this with Acces so I tried to rewrite
the example for Word.
In my document there are a couple of bookmarks and I want to show the names
of the bookmarks in the combobox . This is not a real life project but I'm
just trying to understand the examples in the book.
However, on the getItemLabel event, I get three errors (which seems to have
a sort of logic, since there are 3 bookmarks in the document.
I just don't understand what I'm doing wrong.
This is my VBA code:
Option Explicit
Public grxIRibbonUI As IRibbonUI
Public gvBookmarkList As Variant
Public glngItemCount As Long
Sub PopulateBookmarkArray()
Dim sBookmarkArray() As String
Dim i As Integer
Dim oBookmark As Bookmark
If ActiveDocument.Bookmarks.Count > 0 Then
glngItemCount = ActiveDocument.Bookmarks.Count
For Each oBookmark In ActiveDocument.Content.Bookmarks
If i = 0 Then
ReDim sBookmarkArray(i)
Else
ReDim Preserve sBookmarkArray(i)
End If
sBookmarkArray(i) = oBookmark.Name
i = i + 1
Next
WordBasic.sortarray sBookmarkArray()
gvBookmarkList = sBookmarkArray()
End If
Set oBookmark = Nothing
End Sub
'Callback for customUI.onLoad
Sub rxIRibbonUI_onLoad(ribbon As IRibbonUI)
Set grxIRibbonUI = ribbon
Call PopulateBookmarkArray
grxIRibbonUI.Invalidate
End Sub
Sub GetItemID(control As IRibbonControl, index As Integer, ByRef id)
id = "RxcboBookmark" & index
End Sub
'Callback for RxcboBookmark onChange
Sub RxcboBookmark_Click(control As IRibbonControl, text As String)
Application.StatusBar = text
End Sub
'Callback for RxcboBookmark getItemCount
Sub RxcboBookmark_getItemCount(control As IRibbonControl, ByRef returnedVal)
returnedVal = glngItemCount
End Sub
'Callback for RxcboBookmark getItemLabel
Sub RxcboBookmark_getItemLabel(control As IRibbonControl, index As Integer,
ByRef returnedVal)
returnedVal = gvBookmarkList(index)
End Sub
This is the XML for the file:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="rxIRibbonUI_onLoad">
<ribbon>
<tabs>
<tab id="MyTab"
label="MyTab"
insertBeforeMso= "TabHome">
<group id="MyId"
label="MyTools" >
<comboBox id="RxcboBookmark"
label = "Review list"
onChange = "RxcboBookmark_Click"
getItemID= "RxcboBookmark_getItemID"
getItemCount="RxcboBookmark_getItemCount"
getItemLabel="RxcboBookmark_getItemLabel" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
Why am I getting an error on the event? What is wrong in my code?
Another question I have regarding this topic is I don't seem to be able to
understand where the array is hooked on the combobox.
I would expect something like the oldfashioned additem of a
commandbarcontrol, but all I see is a reference to the array on the
GetItemLabel event. Is that really all there's to it? Does this means the
items aren't filled until the user is entering the combobox itself? (I mean
changing the text inside it, or using the arrow beside it)
And how would I set a preferred listindex for such a combobox?
Any assistance is very appreciated.
TIA.
I hope this is the appropriate group for this question. I didn't now exactly
where to post this.
I am working my way throught the RibbonX book but get stranded on the
chapter of dynamically filled comboboxes.
In the book there's only an example of this with Acces so I tried to rewrite
the example for Word.
In my document there are a couple of bookmarks and I want to show the names
of the bookmarks in the combobox . This is not a real life project but I'm
just trying to understand the examples in the book.
However, on the getItemLabel event, I get three errors (which seems to have
a sort of logic, since there are 3 bookmarks in the document.
I just don't understand what I'm doing wrong.
This is my VBA code:
Option Explicit
Public grxIRibbonUI As IRibbonUI
Public gvBookmarkList As Variant
Public glngItemCount As Long
Sub PopulateBookmarkArray()
Dim sBookmarkArray() As String
Dim i As Integer
Dim oBookmark As Bookmark
If ActiveDocument.Bookmarks.Count > 0 Then
glngItemCount = ActiveDocument.Bookmarks.Count
For Each oBookmark In ActiveDocument.Content.Bookmarks
If i = 0 Then
ReDim sBookmarkArray(i)
Else
ReDim Preserve sBookmarkArray(i)
End If
sBookmarkArray(i) = oBookmark.Name
i = i + 1
Next
WordBasic.sortarray sBookmarkArray()
gvBookmarkList = sBookmarkArray()
End If
Set oBookmark = Nothing
End Sub
'Callback for customUI.onLoad
Sub rxIRibbonUI_onLoad(ribbon As IRibbonUI)
Set grxIRibbonUI = ribbon
Call PopulateBookmarkArray
grxIRibbonUI.Invalidate
End Sub
Sub GetItemID(control As IRibbonControl, index As Integer, ByRef id)
id = "RxcboBookmark" & index
End Sub
'Callback for RxcboBookmark onChange
Sub RxcboBookmark_Click(control As IRibbonControl, text As String)
Application.StatusBar = text
End Sub
'Callback for RxcboBookmark getItemCount
Sub RxcboBookmark_getItemCount(control As IRibbonControl, ByRef returnedVal)
returnedVal = glngItemCount
End Sub
'Callback for RxcboBookmark getItemLabel
Sub RxcboBookmark_getItemLabel(control As IRibbonControl, index As Integer,
ByRef returnedVal)
returnedVal = gvBookmarkList(index)
End Sub
This is the XML for the file:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="rxIRibbonUI_onLoad">
<ribbon>
<tabs>
<tab id="MyTab"
label="MyTab"
insertBeforeMso= "TabHome">
<group id="MyId"
label="MyTools" >
<comboBox id="RxcboBookmark"
label = "Review list"
onChange = "RxcboBookmark_Click"
getItemID= "RxcboBookmark_getItemID"
getItemCount="RxcboBookmark_getItemCount"
getItemLabel="RxcboBookmark_getItemLabel" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
Why am I getting an error on the event? What is wrong in my code?
Another question I have regarding this topic is I don't seem to be able to
understand where the array is hooked on the combobox.
I would expect something like the oldfashioned additem of a
commandbarcontrol, but all I see is a reference to the array on the
GetItemLabel event. Is that really all there's to it? Does this means the
items aren't filled until the user is entering the combobox itself? (I mean
changing the text inside it, or using the arrow beside it)
And how would I set a preferred listindex for such a combobox?
Any assistance is very appreciated.
TIA.