|
上面解决方案正确,程序可以优化,完整的程序如下:
1 前面的不变:
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef destination As Any, ByRef source As Any, ByVal length As Long)
Public Rib as IRibbonUI
Sub RibX_OnLoad(ribbon As IRibbonUI)
SaveSetting "CustomUI",ThisWorkbook.name, "RibbonPointer", ObjPtr(ribbon)
Set Rib=ribbon
End Sub
2 函数部分优化:
Function GetRibbon() As Object ''指针已存在注册表中,无需另外传递,其他多余部分删去
Dim objRibbon As Object, lngRibPointer As Long
lngRibPointer = GetSetting("CustomUI", ThisWorkbook.Name, "RibbonPointer")
CopyMemory objRibbon, lngRibPointer, LenB(lngRibPointer)
Set GetRibbon = objRibbon
End Function
3 调用:
可以在VBA任何程序段中调用,(我是在错误处理部分调用),如
sub a()
.....
Set Rib = GetRibbon
Rib.Invalidate
end sub
|
评分
-
1
查看全部评分
-
|