Send text to Word

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
dellarocco88
Posts: 35
Joined: 07 Apr 2022, 01:34

Send text to Word

Post by dellarocco88 » 01 Jun 2023, 04:01

I'm just trying to create a simple little catalog with lines of text that I want to put in to my Word.

Basically I write som text, start my script and click on the text and it should be sent to Word.

When I click on the text, it don't go back to word thu, I need to click on the text and then quick ass hell manually go back to word for the text to go in.
Don't seem to work with Send {Alt}+{TAB}.

What could I do? :)

Code: Select all

#w::

Gui, 1:Add, Text, vVar1 gGo1, Bla bla
Gui, 1:Add, Text, vVar2 gGo2, Bla bla2

Gui, 1:Show,, Window

Go1:
Send {Alt}+{TAB}
Send Your awesome!
Return

Go2:
Send {Alt}+{TAB}
Send You Suck!
Return

User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Send text to Word

Post by WalkerOfTheDay » 01 Jun 2023, 04:42

Instead of using ALT-TAB, you could use WinActivate.

Also, this is V1 code, so you asked the question in the wrong section.

Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Re: Send text to Word

Post by Krd » 01 Jun 2023, 05:12

You gonna be my first try to help. :)

Using mikeys converter for AHKv2:

Code: Select all

myGui := Gui()
myGui.Add("Text", "vVar1", "Bla bla").OnEvent("Click", Go1)
myGui.Add("Text", "vVar2", "Bla bla2").OnEvent("Click", Go2)
myGui.Title := "Window"
myGui.Show()

Go1(*)
{
Send("{Alt Down}{Tab}{Alt Up}")
Sleep 1000
Send("Your awesome!")
}

Go2(*)
{
Send("{Alt Down}{Tab}{Alt Up}")
Sleep 1000
Send("You Stuck!")
}

User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: Send text to Word

Post by mikeyww » 01 Jun 2023, 05:34

Code: Select all

; This script pastes text selected from a GUI into Microsoft Word
#Requires AutoHotkey v2.0
txt := '
(
Text1
Text2
)'
gui1 := Gui()
gui1.SetFont('s10')
For each, line in StrSplit(txt, '`n')
 gui1.AddText('w300', line).OnEvent('Click', txt_Click)

#HotIf WinExist('ahk_exe WINWORD.exe')
#w::gui1.Show
#HotIf

txt_Click(txt, info) {
 gui1.Submit
 A_ClipBoard := txt.Text
 ComObjActive("Word.Application").Selection.Paste
}
Last edited by mikeyww on 01 Jun 2023, 05:38, edited 1 time in total.

User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Send text to Word

Post by WalkerOfTheDay » 01 Jun 2023, 05:37

Even with the V2 code, I would replace the ALT-TAB which is unreliable.
Something like this:

Code: Select all

myGui := Gui()
myGui.Add("Text", "vVar1", "Bla bla").OnEvent("Click", Go1)
myGui.Add("Text", "vVar2", "Bla bla2").OnEvent("Click", Go2)
myGui.Title := "Window"
myGui.Show()

Go1(*)
{
    WinActivate("ahk_exe WINWORD.EXE")
    Sleep 1000
    Send("Your awesome!")
}

Go2(*)
{
    WinActivate("ahk_exe WINWORD.EXE")
    Sleep 1000
    Send("You Stuck!")
}

Post Reply

Return to “Ask for Help (v2)”