Consulting

Results 1 to 7 of 7

Thread: duplicate groups on my custom tab :-(

  1. #1
    VBAX Regular
    Joined
    Oct 2015
    Posts
    16
    Location

    duplicate groups on my custom tab :-(

    Hi,

    I have used the custom UI editor to add a custom group to a shared custom tab in normal.dotm.

    If I open Word, then edit, save and close Word (and consequently the new document Doc1.docx which was presented to me upon opening Word) WITHOUT using any of the custom functionality on the custom tab, the new file re-opens successfully. (Presumably the new file is based on normal.dotm?).

    If I open Word, then edit, use some of the custom functionality on the custom tab, save and then close Word, when I reopen the new file Doc1.docx, a duplicate custom group appears on the custom tab. This appears to be because the onLoad routine (corresponding to the normal.dotm custom UI XML) gets run twice ...

    Any idea how I can stop this happening, please?

    Many thanks, Helen.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    I don't see anything wrong with your code. ...
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Regular
    Joined
    Oct 2015
    Posts
    16
    Location
    Quote Originally Posted by SamT View Post
    I don't see anything wrong with your code. ...
    Here is the XML code (had to remove the URL from customUI xmlns as VBA Express would not allow me to post it ...):

    <customUI xmlns="schemas.microsoft.com/office/2006/01/customui" xmlns:x="myNameSpace"onLoad="RibbonControl.Onload">
    <ribbon startFromScratch="false">
    <tabs>
    <tab idQ="x:CustomTab"label="Transcription">
    <group id="customGroup"label="Templates">
    <dropDown id="attachTemplate"label="Attach template"
    getItemCount="RibbonControl.GetItemCount"
    getItemLabel="RibbonControl.GetItemLabel"
    getSelectedItemIndex="RibbonControl.GetSelectedItemIndex"
    onAction="RibbonControl.AttachTemplate" >
    </dropDown>
    </group>
    </tab>
    </tabs> </ribbon
    </customUI>


    And now the VBA which is contained within its' own module in normal.dotm:

    Option Explicit
    
    Public myRibbon As IRibbonUI

    Sub Onload(ribbon As IRibbonUI)
      'Creates a ribbon instance for use in this project
      Set myRibbon = ribbon
    End Sub
    'Callback for DropDown GetItemCount
    Sub GetItemCount(ByVal control As IRibbonControl, ByRef count)
      'Tell the ribbon to show 5 items in the dropdown
      count = 5
    End Sub
    'Callback for DropDown GetItemLabel
    Sub GetItemLabel(ByVal control As IRibbonControl, Index As Integer, ByRef label)
      'This procedure fires once for each item in the dropdown. Index is _
       received as 0, 1, 2, etc. and label is returned.
      label = Choose(Index + 1, "--", "Giant Print", "bookx", "magx", "chess")
    End Sub
    'Callback DropDown GetSelectedIndex
    Sub GetSelectedItemIndex(ByVal control As IRibbonControl, ByRef Index)
      'This procedure is used to ensure the first item in the dropdown is selected _
       when the control is displayed
      Select Case control.ID
        Case Is = "attachTemplate"
          'Index = Index
        Case Else
          'Do nothing
      End Select
    End Sub
    'Callback for DropDown onAction
    Sub AttachTemplate(ByVal control As IRibbonControl, selectedID As String, selectedIndex As Integer)
    Dim DummyVar As Integer
      Select Case selectedIndex
      
        Case 0 '--
           'do nothing
           Exit Sub
           
        Case 1 'Giant Print
    ' taken from sub gwAddGPTemplate
    '       On Error GoTo errHandler
           With ActiveDocument
               .UpdateStylesOnOpen = True
               .AttachedTemplate = "C:\sgmlutil\template\word\bookgp.dot"
           End With
           MsgBox ("Giant Print template attached!")
          Exit Sub
          
        Case 2 'bookx
    '       On Error GoTo errHandler
           With ActiveDocument
               .UpdateStylesOnOpen = True
               .AttachedTemplate = "C:\sgmlutil\template\word\bookx.dot"
           End With
           MsgBox ("bookx template attached!")
           Exit Sub
       
        Case 3 'magx
    '       On Error GoTo errHandler
           With ActiveDocument
               .UpdateStylesOnOpen = True
               .AttachedTemplate = "C:\sgmlutil\template\word\magx.dot"
           End With
           MsgBox ("magx template attached!")
           Exit Sub
           
        Case 4  'chess
    '       On Error GoTo errHandler
           With ActiveDocument
               .UpdateStylesOnOpen = True
               .AttachedTemplate = "C:\sgmlutil\template\word\chess.dot"
           End With
           MsgBox ("chess template attached!")
           Exit Sub
           
      End Select
      
    errHandler: 'from sub gwAddGPTemplate
        If Err.Number = 4248 Then
            Documents.Add
        End If
      
    End Sub
    Last edited by SamT; 06-08-2016 at 08:21 AM. Reason: Added CODE Tags with # Icon

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    I am not sure, but try changing
    Set myRibbon = ribbon
    To
    If myRibbon Is Nothing then Set myRibbon = ribbon
    Also in the Doc before close sub set myRibbon = Nothing
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Since it appears that your custom tab is only used to attach a different template to a document, what happens if you don't share the custom XML, but only


    1. leave it in Normal.dotm or

    2. put it in a separate dotm in C:\Users\userid\AppData\Roaming\Microsoft\Word\STARTUP?

    Something like

    <customUI xmlns="schemas.microsoft.com/office/2006/01/customui" onLoad="RibbonControl.Onload"> 
     <ribbon startFromScratch="false">
     <tabs>
     <tab id="CustomTab" label="Transcription">
     <group id="customGroup" label="Templates">
     <dropDown id="attachTemplate" label="Attach template"
     getItemCount="RibbonControl.GetItemCount"
     getItemLabel="RibbonControl.GetItemLabel"
     getSelectedItemIndex="RibbonControl.GetSelectedItemIndex"
    onAction="RibbonControl.AttachTemplate" > 
     </dropDown> 
     </group>
     </tab>
     </tabs> </ribbon
    </customUI>
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  6. #6
    VBAX Regular
    Joined
    Oct 2015
    Posts
    16
    Location
    Hi Sam, Thanks for your advice. Unfortunately the above doesn't help :-( Cheers, Helen.

  7. #7
    VBAX Regular
    Joined
    Oct 2015
    Posts
    16
    Location
    Hi Paul,

    Although the custom tab is currently used to only attach templates, my plan is to allow other templates (when attached) to add other functionality to the custom tab so I do really need to share the XML for the tab.

    I've tried moving it to a separate template (startup.dotm) in the START UP folder and this seems to have solved the problem!!

    Presumably this is because startup.dotm only gets opened/run once during any Word session? Whereas, presumably normal.dotm gets opened/run at start up and then again whenever a document based upon it is opened?

    Thanks, Helen.
    Last edited by HelenT; 06-15-2016 at 03:08 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •