Log in

View Full Version : [SOLVED:] MS Word, activate the Selection and Visibility Pane from within VBA code



mslonik
04-02-2019, 02:15 AM
Dear Forum,

my goal is to activate (open / switch on / enable) the "Selection and Visibility Pane" from within VBA code (Word macro).

What is the "Selection and Visibility Pane"? This is part of Microsoft Word GUI. This tool is meant for working with objects in your document, particularly shapes and images. To use the tool, display the Page Layout tab of the ribbon and click the Selection Pane tool in the Arrange group. The pane appears at the right side of the document. (The Selection Pane tool is a toggle; clicking it a second time hides the pane.)

What I already tried to do prior to asking a question here, was searching the following resources:

https://docs.microsoft.com/en-us/office/vba/api/word.application.dialogs
https://docs.microsoft.com/en-us/office/vba/api/word.taskpanes

Without a hit till now. I can't find any hint, how this pane is named or where to search for it.

My MS Word: 2010 Professional Plus
My operating system: Windows 7 Enterprise

Kind regards, mslonik

macropod
04-02-2019, 03:44 AM
my goal is to activate (open / switch on / enable) the "Selection and Visibility Pane" from within VBA code (Word macro).
Why, as in what is the purpose of doing this?

mslonik
04-02-2019, 04:50 AM
I have two keyboards connected to my Windows operating PC at the same time: the first keyboard (black) is used as "ordinary keyboard", the second (grey) runs as "macro keyboard". For almost all keys of the "macro keyboards" I have assigned macros. The macros are specific for Microsoft Word and written in AHK (Auto Hotkey).

There are 3 levels how can I define macros for MS Word using AHK:
a. repeat basic sequence of keys which are pressed to run specific function,
b. define specific shortcut for a Word function,
c. call COM function of MS Word.

The "c" version is at most reliable, elegant and convenient. If I have VBA code, I can quite easily translate it to AHK. So I've thought this is the right forum to ask such a question.

So to sum-up: I'like to have a key at "macro keyboard", which enables / disables view of the "Selection and Visibility Pane" just for my convenience, to apply AHK macro.

I didn't think it could be a challenge.

Kind regards, mslonik

mslonik
04-11-2019, 11:24 PM
Finally I was able to figure it out:



CommandBars("Selection and Visibility").Visible = True
CommandBars("Selection and Visibility").Visible = False


do a trick.

Kind regards, mslonik

DaveM
04-22-2022, 11:21 AM
Hello mslonik,

I was also trying to find a way to pop up the Selection and Visibility pane while in the process of building and grouping some shapes on screen via vba. I found your solution, but found that on first running the macro an error would occur on the first commandbars command.

I found the following suggestion by John Wilson on the StackOverflow site from 2014:

If Not CommandBars.GetPressedMso("SelectionPane") Then CommandBars.ExecuteMso("SelectionPane")

This seemed to cure the first run failures.

Dave