Err50289 Dynamic Ribbon in Protected Project

L

L. Miller

My ribbon load event began having issues when I protected my VBA Project—generating error code 50289, "Can't perform opperation since the project isprotected." My ribbon load event begins to generate the error at: "Set Rib= ribbon". Has anyone else run into this? Thanks in advance, Lonnie M.

'Callback for customUI.onLoad
Sub rxIRibbonUI_onLoad(ribbon As IRibbonUI)
Dim lngRibPtr As Long
' Store the custom ribbon UI Id (Memory Location) in a static variable.
' This is done once during load of UI. I.e. during workbook open.
Set Rib = ribbon
lngRibPtr = ObjPtr(ribbon)
' Write pointer to named range
' The named range that is used was created outside of the code
' The Rib object seems to drop whenever a sheet is added or deleted.
' This allows the ribbon to be refreshed even if Rib is empty,
' preventing the user from having to save, close, and re-open the file.
ThisWorkbook.Names("iRibbonMemoryLoc").Value = lngRibPtr
Dim shCname$, noneStr$
noneStr = " "
shCname = ActiveSheet.Parent.VBProject.VBComponents(ActiveSheet.CodeName).Properties("_CodeName")
If Environ("USERNAME") <> "lmiller1" And Not LogIn Then
If InStr(shCname, "Calc") > 0 Then
Call RefreshRibbon("Calc*")
ElseIf InStr(shCname, "Template") > 0 Then
Call RefreshRibbon("CalcTempSheetGrp")
Else
Call RefreshRibbon(noneStr)
End If
Else
Call RefreshRibbon("*")
End If
End Sub
Function GetRibbon(lngRibPtr As Long) As Object
'This function is called to restore the ribbon object (Rib)
'When a worksheet is deleted it would cause the Ribbon to be lost
'and the sheet events that triggered the contectual tabs and groups
'stopped working.
Dim objRibbon As Object
CopyMemory objRibbon, lngRibPtr, 4
Set GetRibbon = objRibbon
Set objRibbon = Nothing
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top