AHK and VBA of MS Word, shape to selected canvas

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:

AHK and VBA of MS Word, shape to selected canvas

28 Mar 2019, 11:10

Dear Forum,

I'd like to add a shape to the selected canva within existing MS Word document. I can't figure out how to do that. This time macro recorder of MS Word doesn't bring any help.

My unsuccessful attempts:

Code: Select all

	oWord.ActiveDocument.Selection.Shapes.AddShape(msoShapeRectangle := 1, 100, 100, 70, 30)
	oWord.Selection.Range.Shapes.CanvasItems.AddShape(msoShapeRectangle := 1, 100, 100, 70, 30)
	oWord.Selection.ChildShapeRange.AddShape(msoShapeRectangle := 1, 100, 100, 70, 30)
	
	oWord.Selection.CanvasShapes.AddShape(msoShapeRectangle := 1, 100, 100, 70, 30)
	oWord.Selection.AddShape(msoShapeRectangle := 1, 100, 100, 70, 30)
I've found some hints here:
...//docs.microsoft.com/en-us/office/vba/api/word.selection.childshaperange
and here:
...//docs.microsoft.com/en-us/office/vba/api/word.canvasshapes.addshape

(Above links are out-of-order because of forum security rules).

but it doesn't solve my issue.

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
mslonik
Posts: 144
Joined: 21 Feb 2019, 04:38
Location: Poland
Contact:

Re: AHK and VBA of MS Word, shape to selected canvas

29 Mar 2019, 02:49

Small progress. Now I'm able to add a shape to a new canva in a document:

Code: Select all

oWord := ComObjActive("Word.Application")
shpCanvas := oWord.ActiveDocument.Shapes.AddCanvas(100, 75, 150, 200)
shpCanvas.CanvasItems.AddShape(msoShapeRectangle := 1, 100, 100, 70, 30)
oWord := ""
I'm able also to select existing canva:

Code: Select all

oWord := ComObjActive("Word.Application")
oWord.Selection
oWord := ""
I'm still unable to figure out how to add a new object to a selected canva.

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
mslonik
Posts: 144
Joined: 21 Feb 2019, 04:38
Location: Poland
Contact:

Re: AHK and VBA of MS Word, shape to selected canvas

29 Mar 2019, 03:40

Finally, I solved it:

Code: Select all

oWord := ComObjActive("Word.Application")
oWord.Selection.ShapeRange.CanvasItems.AddShape(msoShapeRectangle := 1, 100, 100, 70, 30)
oWord := "" ; Clear global COM objects when done with them
Now it seems easy...

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:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, jameswrightesq and 282 guests