none
word backstage combo box event RRS feed

  • Question

  • 1st off let me say my experience with programming is limited so please go easy on me :)
    Background Info:
    I currently push workgroup templates via a GPO based on city OU. When a user selects file tab>new>my templates, the new from template box comes up, with a tab for each template type. Each city has 9 different template types which are pretty much the same but do have differences based on city and provincial regulations. We are at the point now where about 30% of my users need access to all city templates as projects are now shared between cities. Previously we were allowing the users to browse the share to use templates from other cities, but found they were just copying them all to the desktop, and they were always using templates that werent current. I tried implementing the solution found herehttp://technet.microsoft.com/en-us/library/cc178976.aspx  but you cant have a folder structure and the user would have to scroll through all template types

    I have created a com addin that adds a tab to word 2010 backstage.

    From different sample code and some patience I have managed to get as far as a new tab. On this tab I have 2 groups in 1 column, with 2 combo boxes and 1 button in grp1. cbo1 is populated with all the cities we have a presence in cbo2 is populated with all the different word template types (engineering, project admin and so on). Can anyone point me along the way so that when a users selects a city and template type, then clicks the view templates button the returned templates will show up in grp2(available templates)?

    I guess I am looking for the same type of behaviour that the above technet article produces when it resolves the ServiceURL and reads the template configuration XML. I am not sure if it should be done from the XML file or fron the connect.vb file that was created when I made the project in VS2010 from other project types>extensibility>shared add-in

    Here is my code from the XML

    <?xml version="1.0" encoding="utf-8" ?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
     
    <backstage>
       
    <tab id="customTab" label="S + A Templates" insertAfterMso="TabInfo" >
         
    <firstColumn>
           
    <group id="customGroup" label="S+A Templates">
             
    <primaryItem>
               
    <button id="btnButton" label="View Templates" imageMso="Folder" onAction="OnAction"/>
             
    </primaryItem>
             
    <topItems>
               
    <layoutContainer id="layoutTwo" layoutChildren="horizontal">
                 
    <comboBox id="cboComboBox" label="Select City" >
                   
    <item id="item1" label="Toronto"/>
                   
    <item id="item2" label="Ottawa"/>
                   
    <item id="item3" label="Edmonton"/>
                   
    <item id="item4" label="Burnaby"/>
                   
    <item id="item5" label="Kelowna"/>
                   
    <item id="item6" label="Victoria"/>
                 
    </comboBox>
                 
    <comboBox id="cboComboBox2" label="template Type" >
                   
    <item id="item7" label="01-Proposal"/>
                   
    <item id="item8" label="02-Project Admin"/>
                   
    <item id="item9" label="03-Permit Docs"/>
                   
    <item id="item10" label="04-Construction Admin"/>
                   
    <item id="item11" label="05-Inter-Office"/>
                   
    <item id="item12" label="06-Prime Consultant"/>
                   
    <item id="item13" label="07-CheckLists"/>
                   
    <item id="item14" label="08-FootPrint"/>
                   
    <item id="item15" label="09-Test-Dont Use"/>
                 
    </comboBox>
                
    </layoutContainer>
             
    </topItems>
           
    </group>
           
    <group id="grpTwo" label="Available Templates" visible="true" >
           
    </group>

         
    </firstColumn>
       
    </tab>
     
    </backstage>
    </customUI>

    Here is my code from connect.vb

    imports Extensibility
    Imports System.Runtime.InteropServices Imports Office = Microsoft.Office.Core
    Imports Word = Microsoft.Office.Interop.Word




    <GuidAttribute("D09E2A2F-1A72-431F-AEB9-1EF84E533420"), ProgIdAttribute("BackstageComAddin.Connect")> _
    Public Class Connect

       
    Implements Extensibility.IDTExtensibility2, Office.IRibbonExtensibility

       
    Private applicationObject As Word.Application

           
    Private addInInstance As Object

    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
    = application
            addInInstance
    = addInInst
    End Sub
       
    Public Function GetCustomUI(ByVal RibbonID As String) As String Implements Microsoft.Office.Core.IRibbonExtensibility.GetCustomUI
           
    Return BackStageCOMAddin.My.Resources.customUI
       
    End Function

       
    Sub OnAction(ByVal control As Office.IRibbonControl)
            MessageBox
    .Show("Please select from available Templates")
       
    End Sub

    End Class

    Thanks in advance to all that may help!!!!!





    • Edited by WGP47 Monday, February 27, 2012 7:37 PM
    Monday, February 13, 2012 8:01 PM

Answers

  • Hi,

    this is a link to part 3 of a series on customizing the Fluent User Interface (Ribbon). in Part 3 the various callbacks are listed.

    http://msdn.microsoft.com/en-us/library/aa722523(v=office.12).aspx

    this article discusses using the FileDialogClass

    http://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog.aspx#Y7744

    In your Custom UI xml you would add the OnChange Attribute for the CBO

    <comboBoxid="cboComboBox"label="Template Type" onChange = "getTType">

    The callback method might look like this:

     Public Sub getTType(ByVal control As Office.IRibbonControl, ByVal text As String)
            strType = text
          showDirTemplates(strType)
      
        End Sub

    The selected value would then be passed to another function something like this:
      Public Sub showDirTemplates(ByVal folder As String)
            Dim openDiag As OpenFileDialog = New OpenFileDialog()
            opendiag.InitialDirectory = "[path to templates folder]\" & folder
            openDiag.Filter = "dot files(*.dot)|*.dot|dotm files(*.dotm)|*.dotm |dotx files(*dotx)|*.dotx|All files (*.*)|*.*"

            Dim myTemplate As String
            If openDiag.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
                Try
                    myTemplate = openDiag.FileName.ToString()

                   WordApplication.Documents.Add(myTemplate) 'creates a new document based on the selected template
                   
                Catch Ex As Exception
                    MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
               
                End Try
            End If

        End Sub

    Hope that this helps.

    Harold


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Harold Kless Microsoft Online Community Support

    Monday, February 27, 2012 8:47 PM
    Moderator

All replies

  • Hi,

    The functional code is added to Connect.vb. The general process like below, however, you will need to look further into dynamically customize the fluent UI: http://msdn.microsoft.com/en-us/library/aa338202(v=office.12).aspx#OfficeCustomizingRibbonUIforDevelopers_Dynamically

    if there's anything unclear, Please let me know, I'll try to assist. 

    1. Create the COM Add-in Project
    2. Add Code to Give the Controls Functionality (Connect.vb)
    3. Add XML to the Project to Create the Tab and Controls
    4. Install the Add-in and Test the Solution

    I'm referring to: http://msdn.microsoft.com/en-us/library/ff936212.aspx#odc_office14_qn_CreateBackstageCustomTab_AddXMLDocumentCreateCommand

    Best Regards,


    Forrest Guo | MSDN Community Support | Feedback to us

    Wednesday, February 15, 2012 3:28 PM
    Moderator
  • Hi Forrest

    I did use the sample code above to create the backstage and just modified it to suit my needs.

    i did look into the top link but i think its out of my league really. I am an mcse and not a programmer and judging by the response I am getting it must not be so cut and dry so to speak. Perhaps even if I could get the regular new from template dialogue box to come up with the template types to pop up would be good. I definitely appreciate the reply and really hope you or someone can help me out here

    Thursday, February 16, 2012 12:46 PM
  • Hi, My reply above may not detail enough, so should you have any specific trouble in this process, please let me know, this way we keep on same page and I know the progress.

    Best Regards,


    Forrest Guo | MSDN Community Support | Feedback to us

    Tuesday, February 21, 2012 4:05 AM
    Moderator
  • HI,

    I have a sense of what you are trying to do and we may best address this in a support incident working with our Word or Office development to guide you through this project.

    Upon review of your customUI code I would add a OnChange attribute to the comboboxes and use this to get the value selected by the user. Pass those selections to a string variable that the OnAction button will read and evaluate which folder contains the templates to display.

    I think for simplicity I would suggest displaying a folder dialog rather than trying to use the config.xml approach. Or, you could simple display a list of template that the user would choose.

    This may not be as elegant approach as the built in new dialog, but it would be functional.


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Harold Kless Microsoft Online Community Support

    Friday, February 24, 2012 11:52 PM
    Moderator
  • Hi Harold

    ok...I took your advice and I am simplifying this down

    What I have done now is created a group for each city with 1 combo box
    The combox box lists all template types
    Can u tell me how I can get a folder dialogue box to open @ a network location based on cbo change event? ie: if user selects
    01-Proposal I would like the dialogue box to open the net share that holds these templates

    <?xml version="1.0" encoding="utf-8" ?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
      <backstage> 
        <tab id="customTab" label="S + A Templates" insertAfterMso="TabInfo" >
          <firstColumn>
            <group id ="head" label ="Smith + Andersen Word Templates"
                   getStyle="SAStyle"
                   helperText="Choose your template type From the Drop down Menu." >
            </group>
            <group id="grp1" label="Toronto" >
    
              <primaryItem>
                <button id="btnButton" label="Toronto Templates" imageMso="TableDesign" />
    
              </primaryItem>
              <topItems>
                <layoutContainer id="layout1" layoutChildren="vertical">
                  <comboBox id="cboComboBox" label="Template Type" >
                    <item id="item1" label="01-Proposal"/>
                    <item id="item2" label="02-Project Admin"/>
                    <item id="item3" label="03-Permit Docs"/>
                    <item id="item4" label="04-Construction Admin"/>
                    <item id="item5" label="05-Inter-Office"/>
                    <item id="item6" label="06-Prime Consultant"/>
                    <item id="item7" label="07-CheckLists"/>
                    <item id="item8" label="08-FootPrint"/>
                    <item id="item9" label="09-Test-Dont Use"/>
                  </comboBox>
                </layoutContainer>
              </topItems>
            </group>

    Monday, February 27, 2012 7:33 PM
  • Hi,

    this is a link to part 3 of a series on customizing the Fluent User Interface (Ribbon). in Part 3 the various callbacks are listed.

    http://msdn.microsoft.com/en-us/library/aa722523(v=office.12).aspx

    this article discusses using the FileDialogClass

    http://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog.aspx#Y7744

    In your Custom UI xml you would add the OnChange Attribute for the CBO

    <comboBoxid="cboComboBox"label="Template Type" onChange = "getTType">

    The callback method might look like this:

     Public Sub getTType(ByVal control As Office.IRibbonControl, ByVal text As String)
            strType = text
          showDirTemplates(strType)
      
        End Sub

    The selected value would then be passed to another function something like this:
      Public Sub showDirTemplates(ByVal folder As String)
            Dim openDiag As OpenFileDialog = New OpenFileDialog()
            opendiag.InitialDirectory = "[path to templates folder]\" & folder
            openDiag.Filter = "dot files(*.dot)|*.dot|dotm files(*.dotm)|*.dotm |dotx files(*dotx)|*.dotx|All files (*.*)|*.*"

            Dim myTemplate As String
            If openDiag.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
                Try
                    myTemplate = openDiag.FileName.ToString()

                   WordApplication.Documents.Add(myTemplate) 'creates a new document based on the selected template
                   
                Catch Ex As Exception
                    MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
               
                End Try
            End If

        End Sub

    Hope that this helps.

    Harold


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Harold Kless Microsoft Online Community Support

    Monday, February 27, 2012 8:47 PM
    Moderator