Options.DefaultHighlightColorIndex 改变后刷新内置 Ribbon 按钮,避免退出“文本高亮颜色" [英] Refresh built-in Ribbon button after Options.DefaultHighlightColorIndex change and avoid exiting "Text Highlight Color"

查看:28
本文介绍了Options.DefaultHighlightColorIndex 改变后刷新内置 Ribbon 按钮,避免退出“文本高亮颜色"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力的工作:

  • 通过键绑定激活Text Highlight Color命令(不是问题)
  • 通过相同的键绑定循环 5 个默认的文本突出显示颜色(或者只是突出显示选择,具体取决于在下面的功能之外检查的 selection.type)
    • 在相应按钮(内置功能区)中显示当前颜色
    • 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)

      我遇到的问题:

      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,

      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. 是否有可能继续下去?

      1. Is there a possibility to keep it going?

      如果需要重新启动:有没有比这更好的方法脏/干扰 sendKeys 调用诸如 Text Highlight 之类的命令颜色?

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

      2019-04-03 更新:与此同时,我发现了 IRibbonUI.InvalidateControlMso ControlID 的列表:Office 2016 帮助文件:Office Fluent 用户界面控件标识符

      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

      因此,在创建隐藏的自定义功能区并在 onLoad 上获取句柄后,我可以 zeWdRibbon.InvalidateControlMso "TextHighlightColorPicker" 没有任何引发的错误.

      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.

      是否有可能,Microsoft 只是在不检查 Application.Options.DefaultHighlightColorIndex 的情况下获取默认 imageMso "TextHighlightColorPicker"(黄色),还是我遗漏了什么?

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

      推荐答案

      我每次都这样做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
      

      这篇关于Options.DefaultHighlightColorIndex 改变后刷新内置 Ribbon 按钮,避免退出“文本高亮颜色"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆