COM MS Word, call to GetPressedMso method

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
mslonik
Posts: 144
Joined: 21 Feb 2019, 04:38
Location: Poland
Contact:

COM MS Word, call to GetPressedMso method

20 Apr 2019, 05:54

Dear Forum,

I don't know how to convert the following VBA code to AHK.

VBA code:

Code: Select all

Sub Makro1()
    If Not CommandBars.GetPressedMso("SelectionPane") Then CommandBars.ExecuteMso ("SelectionPane")
End Sub
AHK code which I've been trying:

Code: Select all

oWord := ComObjActive("Word.Application")
if (oWord.CommandBars.GetPressedMso("Selection and Visibility"))
    {
    }	
else
   {
    oWord.CommandBars.ExecuteMso("Selection and Visibility")	
    }	
oWord := "" ; Clear global COM objects when done with them
The first error which I get:

Code: Select all

Error: 0x80070057 - Parameter is not correct
Source: (null)
Description: (null)
HelpFile: (null)
HelpContext: 0

Specifically: GetPressedMso
I've tried even something more trivial:

Code: Select all

oWord.CommandBars.GetPressedMso("Selection and Visibility")
getting the same error code.

What am I doing wrong?

Link to docs.microsoft.com (shorted due to forum security reason):
//docs.microsoft.com/pl-pl/office/vba/api/office.commandbars.getpressedmso

Kind regards, mslonik
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: COM MS Word, call to GetPressedMso method

20 Apr 2019, 09:55

why did u change SelectionPane to Selection and Visibility? this isnt a valid idMso string

Msos for all version:
MS Office 2003/7
MS Office 2010
MS Office 2013
MS Office 2016
User avatar
mslonik
Posts: 144
Joined: 21 Feb 2019, 04:38
Location: Poland
Contact:

Re: COM MS Word, call to GetPressedMso method

21 Apr 2019, 03:15

Dear swagfag,

at first: thank you for your answer. Indeed it helped to change SelectionPane to Selection and Visibility.

Why did I change it? Two reasons for that:

1. Suggestion coming from another forum:
(...)//stackoverflow.com/questions/24970016/how-to-activate-make-visible-enable-show-selection-pane-in-powerpoint-usin

quotation:


Application.CommandBars("Selection")
(note that for PowerPoint 2010 and 2007 the name is "Selection and Visibility")


Unfortunately, as we both realized, I didn't try to change it as my environment is Microsoft Word 2010...

2. My attempt to solve problem in traditional way. The following AHK code works (toggles "Selection and Visibility" pane) except for the first time. Another words: if after starting Microsoft Word I would have clicked "Selection and Visibility" pane, the code works. If not - it doesn't work.

Code: Select all

WordTrue := -1
WordFalse := 0

oWord := ComObjActive("Word.Application")
StateOfSelectionPane := oWord.CommandBars.ExecuteMso("SelectionPane").Visible

if (StateOfSelectionPane = WordTrue)
		{
		oWord.CommandBars("SelectionPane").Visible := WordFalse
		}
	else
		{
		oWord.CommandBars("Selection and Visibility").Visible := WordTrue	
		}
Looking into (...)://docs.microsoft.com/pl-pl/office/vba/api/overview/library-reference/commandbars-members-office
indeed I wasn't able to determine values of idMso. How did you manage to find it? If I understood correctly it has something to do with "Fluent" mechanism. So methods like ExecuteMso are somehow related to "Fluent" and not to CommandBars? As a newbie I feel little bit confused.

Kind regards, mslonik

My scripts on this forum: Hotstrings Diacritic O T A G L E
Please become my patreon: Patreon👍
Written in AutoHotkey text replacement tool: Hotstrings.technology
Courses on AutoHotkey :ugeek:
User avatar
Datapoint
Posts: 300
Joined: 18 Mar 2018, 17:06

Re: COM MS Word, call to GetPressedMso method

21 Apr 2019, 16:48

mslonik wrote:
21 Apr 2019, 03:15
indeed I wasn't able to determine values of idMso. How did you manage to find it?
I think you could google "idMso" and get some good results.

The F7 hotkey from this script will show the commands that are available in your version of Word.
User avatar
mslonik
Posts: 144
Joined: 21 Feb 2019, 04:38
Location: Poland
Contact:

Re: COM MS Word, call to GetPressedMso method

24 Apr 2019, 03:16

You're right, I should use Google for that purpose prior to asking here.

Again I've learnt something useful: my knowledge about MS Word and AHK is still at a preliminary level. Now, after further reading I realized that my confusion is rather ignorance in regard of MS Word API :-) This is a good lesson, as now I'm able to do with AHK something what wasn't possible to me a week ago :-) Thank you!

My scripts on this forum: Hotstrings Diacritic O T A G L E
Please become my patreon: Patreon👍
Written in AutoHotkey text replacement tool: Hotstrings.technology
Courses on AutoHotkey :ugeek:
User avatar
Datapoint
Posts: 300
Joined: 18 Mar 2018, 17:06

Re: COM MS Word, call to GetPressedMso method

28 Apr 2019, 14:25

mslonik wrote:
24 Apr 2019, 03:16
You're right, I should use Google for that purpose prior to asking here.
Thanks, glad it helped. But I didn't mean it like, "Just google it." Just like you, I found it was hard and unintuitive to find the values. The first thing I checked was the Help/IDE but there wasn't anything there.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: haomingchen1998, ntepa, sofista, TAC109, Tvlao and 117 guests