vba - Options.DefaultHighlightColorIndex 更改后刷新内置功能区按钮并避免退出“文本突出显示颜色”
问题描述
我正在努力工作:
- 通过键绑定激活文本突出显示颜色命令(不是问题)
- 通过相同的键绑定循环通过默认文本突出显示颜色的 5 个(或仅突出显示选择,取决于在下面的函数之外检查的 selection.type)
- 在相应按钮中显示当前颜色(内置功能区)
我被困在哪里:
Sub cycleThroughSomeDefaultHighlightColorIndexOptions()
Dim zeNewColor As Long
Select Case Options.DefaultHighlightColorIndex
Case wdYellow: zeNewColor = wdBrightGreen
Case wdBrightGreen: zeNewColor = wdTurquoise
Case wdTurquoise: zeNewColor = wdPink
Case wdBlue: zeNewColor = wdRed
Case wdRed: zeNewColor = wdYellow
Case Else: zeNewColor = wdYellow
End Select
Application.Options.DefaultHighlightColorIndex = zeNewColor
End Sub
不会抛出任何错误,会更改 Application.Options.DefaultHighlightColorIndex,
但不会在相应的(内置功能区主页选项卡)按钮上更新/显示新设置的颜色
并退出文本突出显示颜色模式。
有没有可能继续下去?
如果需要重新启动:有没有比脏/干扰sendKeys更好的方法来调用诸如Text Highlight Color之类的命令?
2019-04-03 更新:
与此同时,我发现了IRibbonUI.InvalidateControlMso ControlID
s 的列出位置:Office 2016 帮助文件:Office Fluent 用户界面控制标识符
因此,在创建隐藏的自定义功能区并在 onLoad 上获取它的句柄后,我可以zeWdRibbon.InvalidateControlMso "TextHighlightColorPicker"
没有任何引发的错误。
但它也没有改变任何东西。
有没有可能,微软只是在不检查 Application.Options.DefaultHighlightColorIndex 的情况下获取默认的 imageMso“TextHighlightColorPicker”(黄色),或者我错过了什么?
解决方案
我每次都做这样的事gRibbon.Invalidate
#If VBA7 Then
Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
#Else
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
#End If
Public gRibbon As IRibbonUI
#If VBA7 Then
Function GetRibbon(ByVal lRibbonPointer As LongPtr) As Object
#Else
Function GetRibbon(ByVal lRibbonPointer As Long) As Object
#End If
Dim objRibbon As Object
Call CopyMemory(objRibbon, lRibbonPointer, LenB(lRibbonPointer))
Set GetRibbon = objRibbon
Set objRibbon = Nothing
End Function
Public Sub OnRibbonLoad(ribbon As IRibbonUI)
Set gRibbon = ribbon
'SAVE SETTINGS TO REGISTRY
SaveSetting "POP", "RIBBON", "ribbonPointer", ObjPtr(gRibbon)
End Sub
Public Sub OnActionButton(control As IRibbonControl)
If gRibbon Is Nothing Then
Set gRibbon = GetRibbon(GetSetting("POP", "RIBBON", "ribbonPointer"))
End If
On Error Resume Next
gRibbon.Invalidate
On Error GoTo 0
End Sub
推荐阅读
- javascript - 网页连接
- image-processing - Mogrify 命令删除图像错误的一面
- python - 使用正则表达式搜索特定单词后面的文本
- apache-storm - 如何修复 Apache Storm Trident 拓扑中的错误“组件:[x] 订阅不存在的组件 [y]”
- asp.net-core - AspNet Core 在表格中将多条记录显示为一行多列
- python-3.x - KeyError:'星期几'
- python - 有什么方法可以将向量转换为欧拉角?
- git - 合并MR时Gitlab CI运行作业
- python - 通用 *args 的 Python 类型提示(特别是 zip 或 zipWith)
- javascript - 如何在 VueJs 中制作表格并在 .NET Core Web 应用程序中添加 MSSQL 数据库接收的值