|
Question : Customizing MS Word 2007 RibbonX - ComboBox OnChange doesn't fire
|
|
I'm creating a custom Ribbon menu for MS Word 2007. I have some working buttons that open specific documents. I'm having trouble with a ComboBox, however.
For the Buttons, I'm using "OnAction" and for the ComboBox, "OnChange".
The buttons work fine. The ComboBox does nothing and I can't figure out why.
Here is the Ribbon.xml:
http://schemas.microsoft.com/office/2006/01/customui"> label="MEMO Template" onAction="OnAction3" size="large" />
================================================================== And here is the Connect.vb ================================================================== Imports Extensibility Imports System.Runtime.InteropServices Imports Microsoft.Office.Core Imports Word = Microsoft.Office.Interop.Word Imports System.Reflection Imports System.IO
#Region " Read me for Add-in installation and setup information. " ' When run, the Add-in wizard prepared the registry for the Add-in. ' At a later time, if the Add-in becomes unavailable for reasons such as: ' 1) You moved this project to a computer other than which is was originally created on. ' 2) You chose 'Yes' when presented with a message asking if you wish to remove the Add-in. ' 3) Registry corruption. ' you will need to re-register the Add-in by building the $SAFEOBJNAME$Setup project, ' right click the project in the Solution Explorer, then choose install. #End Region
791-4A19-A323-7ECD95EF5D86"), ProgIdAttribute("WF1Ribbon.Connect")> _ Public Class Connect Implements Extensibility.IDTExtensibility2 Implements IRibbonExtensibility
Private applicationObject As Word.Application Dim addInInstance As Object
Public Sub OnAction1(ByVal IRibbonControl As Object) applicationObject.Documents.Add("S:\Marketing\MSMENU\letterhead.doc") Dim NewPath As String NewPath = ("F:\") My.Computer.FileSystem.CurrentDirectory = NewPath End Sub Public Sub OnAction2(ByVal IRibbonControl As Object) applicationObject.Documents.Add("S:\Marketing\MSMENU\letterheadpre.doc") Dim NewPath As String NewPath = ("F:\") My.Computer.FileSystem.CurrentDirectory = NewPath End Sub Public Sub OnAction3(ByVal IRibbonControl As Object) applicationObject.Documents.Add("S:\Marketing\MSMENU\memo.doc") Dim NewPath As String NewPath = ("F:\") My.Computer.FileSystem.CurrentDirectory = NewPath End Sub Public Sub OnAction4(ByVal IRibbonControl As Object) applicationObject.Documents.Add("S:\Marketing\MSMENU\envelope.doc") Dim NewPath As String NewPath = ("F:\") My.Computer.FileSystem.CurrentDirectory = NewPath End Sub Public Sub OnAction5(ByVal IRibbonControl As Object) applicationObject.Documents.Add("S:\Marketing\MSMENU\fax.doc") Dim NewPath As String NewPath = ("F:\") My.Computer.FileSystem.CurrentDirectory = NewPath End Sub Public Sub OnChange1(ByVal IRibbonControl As Object) applicationObject.Documents.Add("S:\Marketing\MSMENU\memo.doc")
End Sub
Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnBeginShutdown End Sub
Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnAddInsUpdate End Sub
Public Sub OnStartupComplete(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnStartupComplete End Sub
Public Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnDisconnection End Sub
Public Sub OnConnection(ByVal application As Object, ByVal connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnConnection applicationObject = DirectCast(application, Word.Application) addInInstance = addInInst End Sub
Public Function GetCustomUI(ByVal RibbonID As String) As String Implements Microsoft.Office.Core.IRibbonExtensibility.GetCustomUI Dim asm As Assembly = Assembly.GetExecutingAssembly() Dim stream As Stream = asm.GetManifestResourceStream("WF1Ribbon.Ribbon.xml") Dim reader As New StreamReader(stream) Dim Ribbon As String = reader.ReadToEnd reader.Close() stream.Close() 'Return Ribbon
Return My.Resources.Ribbon End Function End Class ===============================================================
The ComboBox OnChange1 event is at line 58 of Connect.vb. I just put one action in it to test before I add the logic to open a different document for each selection.
What have I missed?
Thanks.
|
|
Answer : Customizing MS Word 2007 RibbonX - ComboBox OnChange doesn't fire
|
|
I discovered what the problem was.
<comboBox id="ComboBox1" label="Department Memos" onChange="OnChange1" supertip="Select your Department to open the Memo Template"> <item id="item1" label="Executive" /> <item id="item2" label="Fiscal" /> <item id="item3" label="Human Resources" /> </comboBox>
The ComboBox control returns only the text of the selected item; whatever is in label="..text..", not the index number of the selection.
So I changed:
Public Sub OnChange1(ByVal IRibbonControl As Object) applicationObject.Documents.Add("S:\Marketing\MSMENU\memo.doc") End Sub
to:
Sub OnChange1(ByVal control As IRibbonControl, ByVal text As String) applicationObject.Documents.Add("http://WebServer../../Marketing/MSMENU/memos/" & text & ".doc") End Sub
...and made all the labels identical to the filenames. The ComboBox works now.
|
|
|
|