Refresh built-in Ribbon button after Options.DefaultHighlightColorIndex change and avoid exiting “Text Highlight Color”

五迷三道 提交于 2021-01-27 13:27:04

问题


What I'm trying to get working:

  • activate the Text Highlight Color command via a keybinding (not the problem)
  • cycle through 5 of the Default Text Highlight Colors via the same keybinding (or just highlighting the selection, depending on selection.type checked outside the function below)
    • showing the current Color in the corresponding button (built-in ribbon)

Where I'm stuck:

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

doesn't throw any error, does change the Application.Options.DefaultHighlightColorIndex,

but doesn't update/show the newly set color on the corresponding (built-in ribbon home tab) button

and just exits out of the Text Highlight Color mode.

  1. Is there a possibility to keep it going?

  2. If it needs to be started again: is there a better way than dirty/interfering sendKeys to call commands like Text Highlight Color?

Update 2019-04-03: In the mean time i found where the IRibbonUI.InvalidateControlMso ControlIDs are listed: Office 2016 Help Files: Office Fluent User Interface Control Identifiers

So after creating a hidden custom ribbon and getting a handle for it on onLoad i could zeWdRibbon.InvalidateControlMso "TextHighlightColorPicker" without any raised error.

But it also doesn't change anything.

Is it possible, that Microsoft just getImages the default imageMso "TextHighlightColorPicker" (yellow) without checking for Application.Options.DefaultHighlightColorIndex , or am I missing something?


回答1:


I do something like that, each time 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


来源:https://stackoverflow.com/questions/55388617/refresh-built-in-ribbon-button-after-options-defaulthighlightcolorindex-change-a

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!