variable in COM Object Word.Application

Get help with using AutoHotkey and its commands and hotkeys
schnoocats
Posts: 14
Joined: 31 Jan 2016, 18:11

variable in COM Object Word.Application

07 Mar 2017, 08:25

Hello,
I am a beginner and i can't find on the forum how to use variables with COM component in word.

In this exemple is it possible to put a variable instead the fixed word "Visit" ?

Code: Select all

oWord :=	ComObjCreate("Word.Application") ; create MS Word object
oWord.Selection.TypeText("Visit ") ; type text
Thanks
User avatar
thenasos
Posts: 79
Joined: 10 Nov 2015, 10:00

Re: variable in COM Object Word.Application

07 Mar 2017, 08:45

Hi,
Created elements by default are hidden, so you need to set visibility.
Also you need to add a new document, to have script to work somewhere.

Code: Select all

sometxt := ", but please bring some flowers "

oWord := ComObjCreate("Word.Application") ; create MS Word object
oWord.visible := true
oWord.Documents.Add()
oWord.Selection.TypeText("Visit" sometxt) ; type text
Try reading about the Object models, should help to maintain sanity ;)
https://msdn.microsoft.com/en-us/library/kw65a0we.aspx
Shrek is love...
schnoocats
Posts: 14
Joined: 31 Jan 2016, 18:11

Re: variable in COM Object Word.Application

07 Mar 2017, 09:19

Ok you don't need "%"!
Thank you

Is it possible to send something like {enter} with this method ?
User avatar
thenasos
Posts: 79
Joined: 10 Nov 2015, 10:00

Re: variable in COM Object Word.Application

07 Mar 2017, 10:19

Anything that is without "" will counted as expresion.
If I remember correctly:
TAB -> `t
Line feed ->`n
Cariage return ->`r

In your case:

Code: Select all

oWord.Selection.TypeText("Visit" sometxt "`r" anotherVar "`r maybe more text `r") 
Shrek is love...
schnoocats
Posts: 14
Joined: 31 Jan 2016, 18:11

Re: variable in COM Object Word.Application

11 Mar 2017, 01:40

Works well, thank you very much !

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], crohn, homeskool, Hulu_Unlucky and 38 guests