Link to home
Start Free TrialLog in
Avatar of David Megnin
David MegninFlag for United States of America

asked on

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:

<?xml version="1.0" encoding="utf-8" ?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
  <ribbon startFromScratch="false">
    <tabs>
      <!--<tab idMso="TabHome" >
      <group id="group1" insertAfterMso="GroupClipboard"  label="Document Templates">
      <button id="button1" imageMso="MailMergeAddressBlockInsert" label="WF1 Letterhead" onAction="OnAction" size="normal" />
            <button id="button3" imageMso="MailMergeGreetingLineInsert" label="For Pre-Printed Stock" onAction="OnAction" size="normal" />
            <button id="button4" imageMso="FilePrepareMenu"  label="MEMO Template" onAction="OnAction" size="normal" />
            <button id="button5" imageMso="EnvelopesAndLabelsDialog" label="Envelope Template" onAction="OnAction" size="normal" />
            <button id="button6" imageMso="PageSetupPageDialog" label="FAX Cover Sheet" onAction="OnAction" size="normal" />-->
      <tab id="tab1" label="WorkForce One" >
        <group id="group1" label="Document Templates">
          <button id="button1" imageMso="MailMergeAddressBlockInsert" label="WF1 Letterhead" onAction="OnAction1" size="large" />
          <button id="button3" imageMso="MailMergeGreetingLineInsert" label="For Pre-Printed Stock" onAction="OnAction2" size="large" />
          <button id="button4" imageMso="FilePrepareMenu"  label="MEMO Template" onAction="OnAction3" size="large" />
          <button id="button5" imageMso="EnvelopesAndLabelsDialog" label="Envelope Template" onAction="OnAction4" size="large" />
          <button id="button6" imageMso="PageSetupPageDialog" label="FAX Cover Sheet" onAction="OnAction5" size="large" />

          <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" />
            <item id="item4" label="Legal" />
            <item id="item5" label="Communications" />
            <item id="item6" label="Operations" />
            <item id="item7" label="MIS" />
            <item id="item8" label="Quality Assurance" />
            <item id="item9" label="Business Services" />
          </comboBox>

          <dialogBoxLauncher>
            <button id="button99" screentip="Select a Standard WorkForce One Document Template" onAction="OnAction" />
          </dialogBoxLauncher>
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>

==================================================================
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

<GuidAttribute("667C25F7-F791-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.
Avatar of RobSampson
RobSampson
Flag of Australia image

Have you tried changing your OnChange1 function to output something, like:
    Public Sub OnChange1(ByVal IRibbonControl As Object)
        MsgBox "Combo box was changed"
    End Sub

And see if that fires?  The rest of it looks normal to me.....according to this example....
http://msdn2.microsoft.com/en-us/library/aa434075.aspx

Regards,

Rob.
ASKER CERTIFIED SOLUTION
Avatar of David Megnin
David Megnin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Great.  You can post a request in the Community Support zone to either PAQ this question, or delete it, including the link to this question.

Regards,

Rob.
Avatar of David Megnin

ASKER

No objections from me.  I appreciate Rob's assistance.