Why a code can't run in ”Microsoft Word“ Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
wtu123
Posts: 19
Joined: 15 Nov 2020, 22:54

Why a code can't run in ”Microsoft Word“

19 Nov 2020, 06:32

I want to copy the text in "Microsoft Word" into the clipboard and output a new text. Why can't it succeed?

The code can work in the "txt" document.

Code: Select all

F9::
Clipboard =
Send ^c
Clipboard := "{{c1::" Clipboard "}}"
Send ^v
Return
User avatar
mikeyww
Posts: 27072
Joined: 09 Sep 2014, 18:38

Re: Why a code can't run in ”Microsoft Word“  Topic is solved

19 Nov 2020, 07:32

It's slow, so you have to wait for it.

Code: Select all

F9::
Clipboard =
Send ^c
ClipWait, 2
text := Clipboard
Clipboard =
Clipboard := "{{c1::" text "}}"
ClipWait, 2
Send ^v
Return
Rohwedder
Posts: 7677
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Why a code can't run in ”Microsoft Word“

19 Nov 2020, 07:35

Hallo,
or shorter:

Code: Select all

F9::
Clipboard =
Send ^c
ClipWait, 2
Clipboard := "{{c1::" Clipboard "}}"
Send ^v
Return
wtu123
Posts: 19
Joined: 15 Nov 2020, 22:54

Re: Why a code can't run in ”Microsoft Word“

19 Nov 2020, 07:36

mikeyww wrote:
19 Nov 2020, 07:32
It's slow, so you have to wait for it.

Code: Select all

F9::
Clipboard =
Send ^c
ClipWait, 2
text := Clipboard
Clipboard =
Clipboard := "{{c1::" text "}}"
ClipWait, 2
Send ^v
Return
Thank you very much, this code solved my problem today. :D :D :D :D :D :bravo: :bravo: :bravo:
User avatar
mikeyww
Posts: 27072
Joined: 09 Sep 2014, 18:38

Re: Why a code can't run in ”Microsoft Word“

19 Nov 2020, 07:37

Re the revision above: my understanding is that it might work or might not work, depending on timing, because there is no wait for the second clip to occur. The clipboard is sometimes slow even outside Microsoft Office.
wtu123
Posts: 19
Joined: 15 Nov 2020, 22:54

Re: Why a code can't run in ”Microsoft Word“

19 Nov 2020, 07:39

Rohwedder wrote:
19 Nov 2020, 07:35
Hallo,
or shorter:

Code: Select all

F9::
Clipboard =
Send ^c
ClipWait, 2
Clipboard := "{{c1::" Clipboard "}}"
Send ^v
Return
Thanks, this code is shorter.
wtu123
Posts: 19
Joined: 15 Nov 2020, 22:54

Re: Why a code can't run in ”Microsoft Word“

19 Nov 2020, 07:41

mikeyww wrote:
19 Nov 2020, 07:37
Re the revision above: my understanding is that it might work or might not work, depending on timing, because there is no wait for the second clip to occur. The clipboard is sometimes slow even outside Microsoft Office.
Thank you, I learned a new way of solving problems.
User avatar
boiler
Posts: 17056
Joined: 21 Dec 2014, 02:44

Re: Why a code can't run in ”Microsoft Word“

19 Nov 2020, 07:48

Is it slow when being assigned text like that? We know it can be slow in completing its paste operation, requiring a delay before clearing or reassigning its contents immediately after sending a paste.
Rohwedder
Posts: 7677
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Why a code can't run in ”Microsoft Word“

19 Nov 2020, 07:50

Clipwait waits to see if clipboard contains anything, not if the content is complete.
You would have to wait with a loop until the content does not change anymore.
User avatar
mikeyww
Posts: 27072
Joined: 09 Sep 2014, 18:38

Re: Why a code can't run in ”Microsoft Word“

19 Nov 2020, 07:55

@boiler, yes, clipboard can be slow to assign text. An example is if a third-party clipboard manager is running. In those cases, there is frequently a short delay whenever the clipboard is populated. It might be 50 ms or so, depending on the circumstances.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: jdfnnl and 135 guests