How to preserve or regain the Id of my custom ribbon UI? - Page 6

Page 6 of 6 FirstFirst ... 456
Results 51 to 57 of 57

Thread: How to preserve or regain the Id of my custom ribbon UI?

  1. #51
    New Member
    Join Date
    Jan 2009
    Posts
    38
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: How to preserve or regain the Id of my custom ribbon UI?

     
    Hello,

    Nobody to answer my question ? I store the pointer in the worksheets(1) of my Addin, in the range("A1"). Is there an inconvenience ? Thanks.

  2. #52
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    UK
    Posts
    30,749
    Post Thanks / Like
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)

    Default Re: How to preserve or regain the Id of my custom ribbon UI?

    No that's fine.

  3. #53
    New Member
    Join Date
    Jan 2009
    Posts
    38
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: How to preserve or regain the Id of my custom ribbon UI?

    Thank you very much RoryA !

  4. #54
    New Member
    Join Date
    Nov 2009
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: How to preserve or regain the Id of my custom ribbon UI?

    Very clever method. Thanks, Rory.

    Any idea how to call a "loadImage" callback after the IRibbonUI.Invalidate method is invoked? I have a callback in the Ribbon XML that points to a custom image I have stored outside the application.

    The parent node in my custom Ribbon XML has two callbacks:

    Code:
    When the application first loads, both callbacks work fine. However, when I run the VBA procedure that invokes the .Invalidate method, only the GetEnabled and GetVisible callbacks in the rest of the XML are invoked, not the callbacks in the parent node.

    Any ideas on how to call at least the "loadImage" callback from the XML after I refresh the ribbon?
    Last edited by anthony.mcgovern; Jun 13th, 2015 at 05:38 PM. Reason: XML not showing up

  5. #55
    New Member
    Join Date
    Nov 2009
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: How to preserve or regain the Id of my custom ribbon UI?

    I'm having trouble putting in the XML with the CODE tags. Anyway, here are the callbacks:

    Code:
    customUI loadImage="[VBA image load procedure]" [XML attrubute called o n L o a d]="[VBA ribbon load procedure]" xmlns="[unique namespace]"
    Last edited by anthony.mcgovern; Jun 13th, 2015 at 05:48 PM.

  6. #56
    New Member
    Join Date
    Nov 2009
    Posts
    10
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: How to preserve or regain the Id of my custom ribbon UI?

    I figured it out:

    I removed the loadImage attribute from the parent node and instead used the getImage attribute in the button node to dynamically change the button image after invoking the iRibbonUI.invalidate method when refreshing the ribbon.

    Problem solved.

  7. #57
    New Member
    Join Date
    Jan 2016
    Posts
    1
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: How to preserve or regain the Id of my custom ribbon UI?

      
    Quote Originally Posted by sebastienm View Post
    Hi Rory,

    First, thank you! I've been looking for this code for quite a while, probably like most users.
    Now, is there a chance that the pointer changes over time without the change being captured?
    (I remember pointers held for too long being an issue with many apis in the past)

    I was thinking about storing the value in Excel's Hidden Name Space:
    Code:
    ''' Write the pointer 
    Application.ExecuteExcel4Macro   _
        "SET.NAME(""RibbonXPointer"",lngRibPtr)"
      
    ''' Read the pointer
    lngRibPtr=Application.ExecuteExcel4Macro("RibbonXPointer")

    The advantages would be:
    - the value of the pointer is centralized and shared across all books, and during the entire Excel session, even when all books are closed but excel is kept open.
    - when a book opens or when it rebuilds the ribbon AND when it has ribbon code, the pointer value can be updated for all books to use (?less chance of a bad pointer?)

    Thanks,
    Sebastien

    Rory, thanks for the original solution of storing a pointer to the ribbon!

    Sebastien, that is a great idea that has resolved an issue I was facing with the Add-in I am developing currently:
    - I have multiple users all running a read-only add-in file that is stored on a network drive.
    - Sometimes a user may have multiple instances of Excel open and this enables the pointer to be stored within the application object, where it is most relevant for my add-in!

    Code:
    Private Function StoreObjectPointer(ByRef TargetObject As Object, ByVal ObjectName As String) As Boolean
        Application.ExecuteExcel4Macro "SET.NAME(""" & ObjectName & """, """ & CStr(ObjPtr(TargetObject)) & """)"
    End Function
    
    Private Function GetObjectFromStoredPointer(ByVal ObjectName As String) As Object
        Dim objRetrieved As Object
        Dim lngObjectPointer As Long
    On Error GoTo ErrTrap
        lngObjectPointer = CLng(Application.ExecuteExcel4Macro(ObjectName))
        CopyMemory objRetrieved, lngObjectPointer, 4
        Set GetObjectFromStoredPointer = objRetrieved
        CopyMemory objRetrieved, 0&, 4
    ErrTrap:
        Set objRetrieved = Nothing
    End Function
    Cheers!

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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

 

 
DMCA.com