This is the way I've started referencing it, based on internet research. Obviously where you actually put your memory reference is flexible. I happened to choose the primary header of my vba addin, but it could go anywhere. If in Excel, you could put it on a hidden sheet. In Powerpoint you could put it in some hidden object, I suppose. The primary help with this was WernerGg at the Code Cage Forums, although their application was in Excel.
Whoops, one clarification. I utilize custom conversion functions (so I have "fCStr" instead of "CStr") which basically just error trap any unexpected errors to return the default value.
So my fCStr(null) will return "", whereas CStr(null) would return an error. Remove the "f" from those two lines of code and the below will work, at least most of the time. Or write your own functions to duplicate the above.
Hope this helps anyone who was looking for it. This functionality was invaluable during my development in 2010, so I thought I would share.
'public variable for our ribbon (for the callbacks)
Public pub_myRibbon As IRibbonUI
'required to store pointers to the ribbon
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(destination As Any, source As Any, ByVal length As Long)
'----------------------------------------------------------------------------------------------
'The onload event-- MS says not to put any sort of dialog pop ups during this
'----------------------------------------------------------------------------------------------
Public Sub onLoad(Ribbon As IRibbonUI)
Dim lRibbonPointer As Long
'load our public variable
Set pub_myRibbon = Ribbon
'*** Store a memory reference to our ribbon object, in case the VDE loses scope
'get our long pointer reference, using the objptr function
lRibbonPointer = ObjPtr(Ribbon)
'put in the header, so we can store notes in the main body of the project
ThisDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.text = fCStr(lRibbonPointer)
'mark this document as saved, so this never triggers a "do you want to save this project?"
ThisDocument.Saved = True
End Sub
'----------------------------------------------------------------------------------------------
'allow us to reference the ribbon, regardless if the public variable has been lost
'utilizes the CopyMemory library
'----------------------------------------------------------------------------------------------
Public Function myRibbon() As IRibbonUI
Dim oRibbon As Object
Dim lRibbonPointer As Long
'if we've lost our scope, recreate it from our stored pointer
If pub_myRibbon Is Nothing Then
'get our pointer
lRibbonPointer = fCLng(ThisDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.text)
'this reloads it from memory
CopyMemory oRibbon, lRibbonPointer, 4
'and restores our public object
Set pub_myRibbon = oRibbon
End If
'return our value
Set myRibbon = pub_myRibbon
End Function