Word 2016: VBA code Style Source checkbox in Reveal Formatting Pane

Stacy Brown
Stacy Brown used Ask the Experts™
on
I'm trying to find some VBA code to automatically check the Distinguish Style Source check box at the bottom of the Reveal Formatting Task pane in Word 2016.

While I can open the Reveal Formatting pane without a problem, I cannot find the command for this checkbox. In trying to record the steps, I only get the command to open the task pane.

Anyone know how to do this? Or if you know of a GPO setting or Reg-Hack I could do instead, that would be fine as well.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Technical Consultant at BrightCarbon
Commented:
OK, so I can see that there is a command to open the pane:

Application.CommandBars.ExecuteMso "RevealFormatting"

Open in new window


or:

Application.TaskPanes(wdTaskPaneRevealFormatting).Visible = True

Open in new window


But having searched through all control IDs for Word 2016, there is nothing with the word "distinguish" in it and in fact, the ExecuteMso method only works for control types button and toggleButton so given this control is a checkBox, you can't do what you're looking for.

I also checked to see if the state of this control was persistent when closing Word, with and without a saved doc, and it's not. So that would point to the fact that the state of the checkbox is not saved in the registry. I also searched the registry for "distinguish" and found nothing here:

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\16.0\Word

Open in new window


A search of the Object Model (VBE / F2) also returned nothing for "distinguish".

The last ditch attempt to access a UI control in an Office app is to use SendKeys (which is very unreliable as it can't detect states) so a variant of this might get you there:

' Works for PowerPoint 2016 but keys may need to be adapted for other versions
Sub RevelFormatDistinguishStyle()
  ' Show the Reveal Formatting Pane
  Application.TaskPanes(wdTaskPaneRevealFormatting).Visible = True
  ' Go to the pane
  SendKeys "{F6}"
  ' Tab backwards to the 1st Options control
  ' (backwards to avoid getting 'stuck' in the 'Formatting of selected text' control
  SendKeys "+{TAB}+{TAB}"
  ' Press the spacebar to tick the Distinguish style source
  SendKeys " "
End Sub

Open in new window


After searching online, I also found this user didn't fid the answer to the same question:

answers.microsoft.com

So my conclusion is that there is no way to do what you want... reliably.
Stacy BrownSenior Applications Administrator

Author

Commented:
Thanks so much for the in-depth analysis Jaime!  Very glad to have the confirmation that there is no real reliable way to do this.
Stacy BrownSenior Applications Administrator

Author

Commented:
While not an actual solution, a very nice in-depth analysis.  I appreciate the time and effort taken immensely!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial