Consulting

Results 1 to 10 of 10

Thread: Solved: Re-connecting the Ribbon after error

  1. #1
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location

    Solved: Re-connecting the Ribbon after error

    I've been Googling for a user-friendly way to reconnect the Ribbon after an error, mostly (in my limited experience so far) after trying to InvalidateControl().

    So far, the recommendations usually involve reloading the workbook or document.

    The best workaround I've come up with is not very elegant, and I don't know how bullet-proof it will be in more circumstances.

    I was wondering if anyone could offer suggestions to make it more robust?


    [VBA]
    Option Explicit
    Public gobjRibbon As IRibbonUI, gobjRibbonBackup As IRibbonUI
    Public gbDetailed As Boolean, gbBrief As Boolean, gbCSheet As Boolean

    Public Sub OnRibbonLoad(ribbon As IRibbonUI)
    Set gobjRibbon = ribbon
    Set gobjRibbonBackup = gobjRibbon
    End Sub

    'callback for View buttons
    Sub ViewPressed(control As IRibbonControl, pressed As Boolean)
    Dim bBeenThere As Boolean

    bBeenThere = False

    On Error GoTo ReinitRibbon
    'Set gobjRibbon = Nothing ' for testing purposes
    With control
    Select Case .id
    Case "togDetailed"
    Call PBOM_Detailed
    gbDetailed = True
    gbBrief = False
    gbCSheet = False
    Case "togBrief"
    Call PBOM_Brief
    gbDetailed = False
    gbBrief = True
    gbCSheet = False
    Case "togCSheet"
    Call PBOM_Csheet
    gbDetailed = False
    gbBrief = False
    gbCSheet = True
    End Select
    End With

    gobjRibbon.InvalidateControl ("togDetailed")
    gobjRibbon.InvalidateControl ("togBrief")
    gobjRibbon.InvalidateControl ("togCSheet")
    bBeenThere = False
    Exit Sub
    ReinitRibbon:
    If Err.Number = 91 And Not bBeenThere And Not gobjRibbonBackup Is Nothing Then
    bBeenThere = True
    Set gobjRibbon = gobjRibbonBackup
    Resume
    Else
    Call MsgBox("Sorry - There was as problem with the Ribbon object, " & vbCrLf & vbCrLf & _
    "so I think you'll have to save and re-load this workbook." & vbCrLf & vbCrLf & _
    "But the good news is you probably didn't lose any data", vbCritical + vbOKOnly, sTitle)
    Exit Sub
    End If
    End Sub
    [/VBA]

    Paul

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    There was a thread in the public NGs on this exact topic recently Paul, and even Ron de Bruin conceded that was the only way that he knew how.
    ____________________________________________
    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
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Thanks

    Good stuff on http://www.rondebruin.nl/. I had been to Ron's site before, but there's SO much there, I missed the QAT info that he has.

    I could not find anything at his site about "re-connecting" the ribbon.

    You wouldn't happen to have the NG thread information would you? Binsearch.info didn't have any hits for the keywords I entered.

    Paul

  4. #4
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi Paul,

    Based on all the experimentation that we did when writing the RibbonX book, Robert Martin & I also have come to the conclusion that the only way to reload the ribbon is to reload the workbook. It is hardly ideal, but an unfortunate reality.
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Hi Ken --

    1. I was at my local Barnes & Nobel bookstore looking for "The Book", not in stock so I have to online order it

    2. You were kind enough to make Chap 14 available online for review -- thanks for that

    From the VBA fragment in my first post, Setting a "backup" RibbonUI variable to the Ribbon in the Ribbon OnLoad, and re-Setting the "real" ribbon On Error to the backup seems to work, at least some times, and avoids having to re-load the file.

    This is pretty deep stuff for me, and I'm sure that there are pitfalls.

    It would be nice of Microsoft to address this (and a few other) issues, since they feel that RibbonX is the wave of the future.

    Thanks again

    Paul

  6. #6
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi Paul,

    Sadly, it doesn't seem to be stocked in the "Brick and Mortar" stores. From what I hear, 99% of computer books are sold online, so they only tend to stock the very best sellers and authors. Being a first time author, I guess we're too much of a risk. I hope that you find it useful when it arrives.

    Chapter 14? I made Chapter 7 available... I didn't know that 14 was out, actually.

    With regards to the backup RibbonUI variable, it's a great approach. The more steps you can take to protect the RibbonUI object the better, but ultimately, I really don't think that you should need to. And ultimately I'd agree on your last point. It would be nice if MS addressed quite a few things.
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Chapter 7 is correct (but I guess you knew that )

    There's SO many computer books out of varying quality that I really like to actually see it before I buy it. That's why I was glad that there was a chapter available, so that I could see that it more than just a re-hash of on line help.

    It's on order now

    Thanks again

    Paul

  8. #8
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    I know this is an old post, but in case it is useful, it is possible to regain the reference to the Ribbon - see this post (and its linked post in MrE).

  9. #9
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    I posted what I do (based on info I found in the above post) in another thread here called Ribbon Object. As I am new, it won't allow me to paste a link.

    Forum Admins-- perhaps your parser should allow links within your own forum

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    Quote Originally Posted by Frosty
    I posted what I do (based on info I found in the above post) in another thread here called Ribbon Object. As I am new, it won't allow me to paste a link.

    Forum Admins-- perhaps your parser should allow links within your own forum
    With 33 posts you should have no trouble posting a link.
    ____________________________________________
    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

Posting Permissions

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