Consulting

Results 1 to 11 of 11

Thread: Ribbon Loading Sequence

  1. #1
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,063
    Location

    Ribbon Loading Sequence

    I am experimenting with a template add-in that will create several variations of a custom tab based on the network username of the user. Since I am working with a stand alone PC without access to a network I similute different usernames with a inputbox and an AutoOpen procedure in the template.

    [VBA]Sub AutoOpen()
    pUserName = InputBox("Enter one of the following user names for this demo (Robert Jones, Greg Maxey, Tim Smith, Betty Rogers", "UserName")
    End Sub
    [/VBA]

    The username created is then used with a GetVisible callback to determine which custom groups to display:

    [VBA]Sub GetVisible(control As IRibbonControl, RtnVal)
    Select Case control.ID
    Case "GrpFrontOffice"
    Select Case pUserName
    Case "Tim Smith", "Mary Allen", "Betty Rogers"
    RtnVal = True
    Case Else
    RtnVal = False
    End Select
    Case "GrpDrJones"
    If pUserName = "Robert Jones" Then RtnVal = True Else: RtnVal = False
    Case "GrpCDRMaxey"
    If pUserName = "Greg Maxey" Then RtnVal = True Else: RtnVal = False
    End Select
    End Sub[/VBA]

    All seemed to be working great until I closed down Word and restarted Word.

    It seems that there is a difference in how the ribbon is loaded when Word is first started.

    When I shutdown and restart Word and then open my template the custom tab is already displayed before the AutoOpen procedure fires to define the username. After that name is provided nothing happens.

    If I close the document (but not Word) and then reopen the document, the custom tab is not displayed. The AutoOpen macro fires and after a username is provided the correct custom tab configuration is displayed.

    To get around this behaviour I altered my AutoOpen procedure as shown:

    [VBA]Sub AutoOpen()
    pUserName = InputBox("Enter one of the following user names for this demo (Robert Jones, Greg Maxey, Tim Smith, Betty Rogers", "UserName")
    On Error Resume Next
    rxIRibbonUI.Invalidate
    End Sub
    [/VBA]

    Is there a reason the ribbon loading sequence is different when Word is first started and is there another (or better way) to control how it loads in situations like this?

    Sample document attached.
    Greg

    Visit my website: http://gregmaxey.com

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master xld's Avatar
    Joined
    Apr 2005
    Posts
    25,095
    Location
    I am not sure what problem you are seeing Greg.

    WIth the docujment as is, I get prompted for the user once I enable content, both when I double-click the file and start Word, and when I close it and re-open it.

    I then commented out the ribbon Invalidate statement and repeated the tests. Again I got prompted for the user and saw their required group.

    I must admit, this surprised me as I had expected that the ribbon stuff would load before the AUtoOpen macro, but in my case it did not seem so.

    BTW, code like this

    [vba]

    If pUserName = "Robert Jones" Then RtnVal = True Else: RtnVal = False
    [/vba]

    can be simplified as

    [vba]

    RtnVal = pUserName = "Robert Jones"
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,063
    Location
    xld,

    The steps I take to reveal the issue is:

    With the on error and validate lines stetted out:

    1. Open Word.
    2. Open the template using File>Open
    3. The file opens with the Longview Tab and Standard group displayed, then the Input box prompt appears.
    4. Enter the user name in the prompt and click OK.
    5. The expected group or groups do not display.
    6. Close the file.
    7. Open the file again using same process.
    8. The file opens with the Home tab displayed and the Input box prompt appears.
    9. Enter the user name in the prompt and click OK.
    5. The expected group or groups display correctly.

    I can repeat this behaviour over and over again by completly closing Word.

    Using the On Error and invalidate method all works as expected regardless if Word is shut down and restarted.

    I'm stumped but can live with the work around.

    Thanks for the coding tip.
    Greg

    Visit my website: http://gregmaxey.com

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master xld's Avatar
    Joined
    Apr 2005
    Posts
    25,095
    Location
    Greg,

    Well that is most odd because I don't see that behaviour at all.

    I start Word, open the template, I get the prompt, and upon selection of a name, I get the chosen group showing. I even changed the code so that Greg Maxey would get the GM group and the Officxe group, and that worked fine, I saw two groups.

    Very odd.

    Bob
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,063
    Location
    Bob,

    Yes it is odd. I thought perhaps that some of my global add-ins might be at play, but after removing everything from the startup folder and ensuring no add-ins were loaded it still behaves as outlined above.

    Wait. Here is another twist. I have Word2003, 2007, and 2010 installed on my PC. The behaviour only occurs with Word2007. Using Word2010 the expected results are seen without the On Error and Invalidate commands even when Word is first started.

    Onece again Word perplexes ;-)
    Greg

    Visit my website: http://gregmaxey.com

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master xld's Avatar
    Joined
    Apr 2005
    Posts
    25,095
    Location
    Well I have 2003 and 2007, but not 2010.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    VBAX Newbie
    Joined
    Jul 2010
    Posts
    5
    Location

    Ribbon Loading

    I tried it both ways. Loaded the same either way, the dialog box displayed, then the ribbon loaded.

    I have Word 2010 only on this computer.

  8. #8
    VBAX Regular
    Joined
    Dec 2006
    Posts
    14
    Location

    CustomUI 2007 & 2010


    Have you tried putting in customxml
    for 2007 and 2010 and CustomXML (all three) you just have the last one in the demo.

    I loaded this on 2010 - it loads properly first time and then it loads the tab and is stopped by the input box.

    I've not tried it on laptop with 2003/2007/2010 all loaded but you do need all three customxml parts as far as I know.

    Janine

  9. #9
    VBAX Regular
    Joined
    Dec 2006
    Posts
    14
    Location

    User Environ

    Hi Greg,

    I put below in and updated your template to 2010 with CustomUI XML and 2010 parts and renamed it as a dotm (template with macros) not a document with macros. Works fine on load and restarting word.

    Are you going to list templates in the dynamic dropdowns?

    The issue with template corruption is common. I have it all the time when I build templates and I just created a clean profile and test templates in there and they work fine.


    Option Explicit
    Dim rxIRibbonUI As IRibbonUI

    Function pUserName() As String
    pUserName = Environ("UserName")
    End Function
    Sub AutoExec()
    'pUserName = InputBox("Enter one of the following user names for this demo (Robert Jones, Greg Maxey, Tim Smith, Betty Rogers", "UserName")
    On Error Resume Next
    rxIRibbonUI.Invalidate
    End Sub

  10. #10
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,063
    Location
    Janine,

    I have it working in both 2007 and 2010. The problem seems to be the loading sequence in Word2007 and that is corrected with the On Error and Invalidate statements.

    I wouldn't really necessarily want the ribbon to load when Word started but when a document based on the template is opened or created.

    The Environ tip is handy. I always forget that one. Thanks.
    Greg

    Visit my website: http://gregmaxey.com

  11. #11
    VBAX Regular
    Joined
    Dec 2006
    Posts
    14
    Location

    demo.dotm

    No problem (very simple) but it works a treat the Environ.
    And it works fine as .dotm I just reran it then.
    It is very fast to load both as a dotm and a docm.
    Janine

Posting Permissions

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