Refresh built-in Ribbon button after Options.DefaultHighlightColorIndex change and avoid exiting “Text Highlight Color”Changing highlighted text to a different colorExcel VBA 2010 - Command buttons stop working with multiple sheets selectedC# Word Interop - Range.HighlightColorIndex returns 999999 - Is that intended?onLoad ribbon callback fails (not firing/working) from Excel VBA .xlamSub disabled after savingHow can I restrict MS-Word to pre-defined styles but still allow inline format changesWith Block Variable not Set — Error when workbook OpenedCommunicating with Outlook 2013 add-in (Skype for Business)ActiveDocument error 4248 in Ribbon onLoad sub

How are the cards determined in an incomplete deck of many things?

When do we use "no women" instead of "no woman"?

Different past tense for various *et words

How do you manage to study and have a balance in your life at the same time?

Why is Mitch McConnell blocking nominees to the Federal Election Commission?

Calculate Landau's function

D Scale Question

How can I store milk for long periods of time?

Divide Numbers by 0

How to run a command 1 out of N times in Bash

How do I get my neighbour to stop disturbing with loud music?

Tasha's Hideous Laughter used on a deaf person?

Can a human variant take proficiency in initiative?

If the government illegally doesn't ask for article 50 extension, can parliament do it instead?

Punishment in pacifist society

How does the search space affect the speed of an ILP solver?

Displaying Time in HH:MM Format

The Justice Thought & System & its Morals?

Single vs Multiple Try Catch

Are there balance issues when allowing attack of opportunity against any creature?

How would a disabled person earn their living in a medieval-type town?

Using font to highlight a god's speech in dialogue

Function of the separated, individual solar cells on Telstar 1 and 2? Why were they "special"?

Should we run PBKDF2 for every plaintext to be protected or should we run PBKDF2 only once?



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


Changing highlighted text to a different colorExcel VBA 2010 - Command buttons stop working with multiple sheets selectedC# Word Interop - Range.HighlightColorIndex returns 999999 - Is that intended?onLoad ribbon callback fails (not firing/working) from Excel VBA .xlamSub disabled after savingHow can I restrict MS-Word to pre-defined styles but still allow inline format changesWith Block Variable not Set — Error when workbook OpenedCommunicating with Outlook 2013 add-in (Skype for Business)ActiveDocument error 4248 in Ribbon onLoad sub






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















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?










share|improve this question





















  • 1





    Take a look at the IRibbonUI.Invaludate method - it might be what you are looking for if you are trying to refresh the ribbon.

    – Victor K
    Apr 1 at 16:02






  • 1





    I believe you can find your answer in this article along with VBA code (run the form) wordarticles.com/Shorts/RibbonVBA/RibbonVBADemo.php

    – user2261597
    Apr 2 at 14:30











  • When I tested your code snippet I got Object Required. Please post everything you need to reproduce the issue. --> stackoverflow.com/help/mcve

    – FreeSoftwareServers
    Apr 4 at 2:06






  • 1





    It's not just the GUI that is displaying the old color. If I change it and then click the button then the value is changed back to the default of 7. So it seems that the ribbon overwrites the value with something it has stored elsewhere.

    – HackSlash
    Apr 4 at 20:44











  • Application.ScreenRefresh would otherwise be the answer.

    – HackSlash
    Apr 4 at 20:48

















3















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?










share|improve this question





















  • 1





    Take a look at the IRibbonUI.Invaludate method - it might be what you are looking for if you are trying to refresh the ribbon.

    – Victor K
    Apr 1 at 16:02






  • 1





    I believe you can find your answer in this article along with VBA code (run the form) wordarticles.com/Shorts/RibbonVBA/RibbonVBADemo.php

    – user2261597
    Apr 2 at 14:30











  • When I tested your code snippet I got Object Required. Please post everything you need to reproduce the issue. --> stackoverflow.com/help/mcve

    – FreeSoftwareServers
    Apr 4 at 2:06






  • 1





    It's not just the GUI that is displaying the old color. If I change it and then click the button then the value is changed back to the default of 7. So it seems that the ribbon overwrites the value with something it has stored elsewhere.

    – HackSlash
    Apr 4 at 20:44











  • Application.ScreenRefresh would otherwise be the answer.

    – HackSlash
    Apr 4 at 20:48













3












3








3








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?










share|improve this question
















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?







vba ms-word






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 3 at 21:38







blub

















asked Mar 28 at 0:53









blubblub

9366 silver badges16 bronze badges




9366 silver badges16 bronze badges










  • 1





    Take a look at the IRibbonUI.Invaludate method - it might be what you are looking for if you are trying to refresh the ribbon.

    – Victor K
    Apr 1 at 16:02






  • 1





    I believe you can find your answer in this article along with VBA code (run the form) wordarticles.com/Shorts/RibbonVBA/RibbonVBADemo.php

    – user2261597
    Apr 2 at 14:30











  • When I tested your code snippet I got Object Required. Please post everything you need to reproduce the issue. --> stackoverflow.com/help/mcve

    – FreeSoftwareServers
    Apr 4 at 2:06






  • 1





    It's not just the GUI that is displaying the old color. If I change it and then click the button then the value is changed back to the default of 7. So it seems that the ribbon overwrites the value with something it has stored elsewhere.

    – HackSlash
    Apr 4 at 20:44











  • Application.ScreenRefresh would otherwise be the answer.

    – HackSlash
    Apr 4 at 20:48












  • 1





    Take a look at the IRibbonUI.Invaludate method - it might be what you are looking for if you are trying to refresh the ribbon.

    – Victor K
    Apr 1 at 16:02






  • 1





    I believe you can find your answer in this article along with VBA code (run the form) wordarticles.com/Shorts/RibbonVBA/RibbonVBADemo.php

    – user2261597
    Apr 2 at 14:30











  • When I tested your code snippet I got Object Required. Please post everything you need to reproduce the issue. --> stackoverflow.com/help/mcve

    – FreeSoftwareServers
    Apr 4 at 2:06






  • 1





    It's not just the GUI that is displaying the old color. If I change it and then click the button then the value is changed back to the default of 7. So it seems that the ribbon overwrites the value with something it has stored elsewhere.

    – HackSlash
    Apr 4 at 20:44











  • Application.ScreenRefresh would otherwise be the answer.

    – HackSlash
    Apr 4 at 20:48







1




1





Take a look at the IRibbonUI.Invaludate method - it might be what you are looking for if you are trying to refresh the ribbon.

– Victor K
Apr 1 at 16:02





Take a look at the IRibbonUI.Invaludate method - it might be what you are looking for if you are trying to refresh the ribbon.

– Victor K
Apr 1 at 16:02




1




1





I believe you can find your answer in this article along with VBA code (run the form) wordarticles.com/Shorts/RibbonVBA/RibbonVBADemo.php

– user2261597
Apr 2 at 14:30





I believe you can find your answer in this article along with VBA code (run the form) wordarticles.com/Shorts/RibbonVBA/RibbonVBADemo.php

– user2261597
Apr 2 at 14:30













When I tested your code snippet I got Object Required. Please post everything you need to reproduce the issue. --> stackoverflow.com/help/mcve

– FreeSoftwareServers
Apr 4 at 2:06





When I tested your code snippet I got Object Required. Please post everything you need to reproduce the issue. --> stackoverflow.com/help/mcve

– FreeSoftwareServers
Apr 4 at 2:06




1




1





It's not just the GUI that is displaying the old color. If I change it and then click the button then the value is changed back to the default of 7. So it seems that the ribbon overwrites the value with something it has stored elsewhere.

– HackSlash
Apr 4 at 20:44





It's not just the GUI that is displaying the old color. If I change it and then click the button then the value is changed back to the default of 7. So it seems that the ribbon overwrites the value with something it has stored elsewhere.

– HackSlash
Apr 4 at 20:44













Application.ScreenRefresh would otherwise be the answer.

– HackSlash
Apr 4 at 20:48





Application.ScreenRefresh would otherwise be the answer.

– HackSlash
Apr 4 at 20:48












1 Answer
1






active

oldest

votes


















0















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





share|improve this answer

























  • This is great for keeping the public ribbon object, which would be set to nothing after an unhandled error, but my problem here seems to be, that there is a second, undocumented kind of Application.Options.DefaultHighlightColorIndex.

    – blub
    Apr 6 at 16:05











  • Sets or returns the colour used to highlight text formatted with the Highlight button. Application.Options.DefaultHighlightColorIndex = wdColorIndex.wdGreen

    – Dmitrij Holkin
    Apr 6 at 21:23











  • Application.Options.DefaultHighlightColorIndex is completely ignored by iRibbonUI.invalidate AND by Application.CommandBars.ExecuteMso "TextHighlightColorPicker" (and the corresponding button) so there has to be a different property that I didn't find until now.

    – blub
    Apr 7 at 13:16











  • try look here bettersolutions.com/word/options/vba-code.htm

    – Dmitrij Holkin
    Apr 7 at 13:48











  • @blub if this GetRibbon function actually gives you a handle on the current ribbon then you should be able to modify the ribbon directly.

    – HackSlash
    Apr 8 at 15:10










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55388617%2frefresh-built-in-ribbon-button-after-options-defaulthighlightcolorindex-change-a%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0















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





share|improve this answer

























  • This is great for keeping the public ribbon object, which would be set to nothing after an unhandled error, but my problem here seems to be, that there is a second, undocumented kind of Application.Options.DefaultHighlightColorIndex.

    – blub
    Apr 6 at 16:05











  • Sets or returns the colour used to highlight text formatted with the Highlight button. Application.Options.DefaultHighlightColorIndex = wdColorIndex.wdGreen

    – Dmitrij Holkin
    Apr 6 at 21:23











  • Application.Options.DefaultHighlightColorIndex is completely ignored by iRibbonUI.invalidate AND by Application.CommandBars.ExecuteMso "TextHighlightColorPicker" (and the corresponding button) so there has to be a different property that I didn't find until now.

    – blub
    Apr 7 at 13:16











  • try look here bettersolutions.com/word/options/vba-code.htm

    – Dmitrij Holkin
    Apr 7 at 13:48











  • @blub if this GetRibbon function actually gives you a handle on the current ribbon then you should be able to modify the ribbon directly.

    – HackSlash
    Apr 8 at 15:10















0















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





share|improve this answer

























  • This is great for keeping the public ribbon object, which would be set to nothing after an unhandled error, but my problem here seems to be, that there is a second, undocumented kind of Application.Options.DefaultHighlightColorIndex.

    – blub
    Apr 6 at 16:05











  • Sets or returns the colour used to highlight text formatted with the Highlight button. Application.Options.DefaultHighlightColorIndex = wdColorIndex.wdGreen

    – Dmitrij Holkin
    Apr 6 at 21:23











  • Application.Options.DefaultHighlightColorIndex is completely ignored by iRibbonUI.invalidate AND by Application.CommandBars.ExecuteMso "TextHighlightColorPicker" (and the corresponding button) so there has to be a different property that I didn't find until now.

    – blub
    Apr 7 at 13:16











  • try look here bettersolutions.com/word/options/vba-code.htm

    – Dmitrij Holkin
    Apr 7 at 13:48











  • @blub if this GetRibbon function actually gives you a handle on the current ribbon then you should be able to modify the ribbon directly.

    – HackSlash
    Apr 8 at 15:10













0














0










0









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





share|improve this answer













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






share|improve this answer












share|improve this answer



share|improve this answer










answered Apr 5 at 8:28









Dmitrij HolkinDmitrij Holkin

2,0043 gold badges21 silver badges61 bronze badges




2,0043 gold badges21 silver badges61 bronze badges















  • This is great for keeping the public ribbon object, which would be set to nothing after an unhandled error, but my problem here seems to be, that there is a second, undocumented kind of Application.Options.DefaultHighlightColorIndex.

    – blub
    Apr 6 at 16:05











  • Sets or returns the colour used to highlight text formatted with the Highlight button. Application.Options.DefaultHighlightColorIndex = wdColorIndex.wdGreen

    – Dmitrij Holkin
    Apr 6 at 21:23











  • Application.Options.DefaultHighlightColorIndex is completely ignored by iRibbonUI.invalidate AND by Application.CommandBars.ExecuteMso "TextHighlightColorPicker" (and the corresponding button) so there has to be a different property that I didn't find until now.

    – blub
    Apr 7 at 13:16











  • try look here bettersolutions.com/word/options/vba-code.htm

    – Dmitrij Holkin
    Apr 7 at 13:48











  • @blub if this GetRibbon function actually gives you a handle on the current ribbon then you should be able to modify the ribbon directly.

    – HackSlash
    Apr 8 at 15:10

















  • This is great for keeping the public ribbon object, which would be set to nothing after an unhandled error, but my problem here seems to be, that there is a second, undocumented kind of Application.Options.DefaultHighlightColorIndex.

    – blub
    Apr 6 at 16:05











  • Sets or returns the colour used to highlight text formatted with the Highlight button. Application.Options.DefaultHighlightColorIndex = wdColorIndex.wdGreen

    – Dmitrij Holkin
    Apr 6 at 21:23











  • Application.Options.DefaultHighlightColorIndex is completely ignored by iRibbonUI.invalidate AND by Application.CommandBars.ExecuteMso "TextHighlightColorPicker" (and the corresponding button) so there has to be a different property that I didn't find until now.

    – blub
    Apr 7 at 13:16











  • try look here bettersolutions.com/word/options/vba-code.htm

    – Dmitrij Holkin
    Apr 7 at 13:48











  • @blub if this GetRibbon function actually gives you a handle on the current ribbon then you should be able to modify the ribbon directly.

    – HackSlash
    Apr 8 at 15:10
















This is great for keeping the public ribbon object, which would be set to nothing after an unhandled error, but my problem here seems to be, that there is a second, undocumented kind of Application.Options.DefaultHighlightColorIndex.

– blub
Apr 6 at 16:05





This is great for keeping the public ribbon object, which would be set to nothing after an unhandled error, but my problem here seems to be, that there is a second, undocumented kind of Application.Options.DefaultHighlightColorIndex.

– blub
Apr 6 at 16:05













Sets or returns the colour used to highlight text formatted with the Highlight button. Application.Options.DefaultHighlightColorIndex = wdColorIndex.wdGreen

– Dmitrij Holkin
Apr 6 at 21:23





Sets or returns the colour used to highlight text formatted with the Highlight button. Application.Options.DefaultHighlightColorIndex = wdColorIndex.wdGreen

– Dmitrij Holkin
Apr 6 at 21:23













Application.Options.DefaultHighlightColorIndex is completely ignored by iRibbonUI.invalidate AND by Application.CommandBars.ExecuteMso "TextHighlightColorPicker" (and the corresponding button) so there has to be a different property that I didn't find until now.

– blub
Apr 7 at 13:16





Application.Options.DefaultHighlightColorIndex is completely ignored by iRibbonUI.invalidate AND by Application.CommandBars.ExecuteMso "TextHighlightColorPicker" (and the corresponding button) so there has to be a different property that I didn't find until now.

– blub
Apr 7 at 13:16













try look here bettersolutions.com/word/options/vba-code.htm

– Dmitrij Holkin
Apr 7 at 13:48





try look here bettersolutions.com/word/options/vba-code.htm

– Dmitrij Holkin
Apr 7 at 13:48













@blub if this GetRibbon function actually gives you a handle on the current ribbon then you should be able to modify the ribbon directly.

– HackSlash
Apr 8 at 15:10





@blub if this GetRibbon function actually gives you a handle on the current ribbon then you should be able to modify the ribbon directly.

– HackSlash
Apr 8 at 15:10








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55388617%2frefresh-built-in-ribbon-button-after-options-defaulthighlightcolorindex-change-a%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현