Improve the speed of pasting from excel Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Astroboy12
Posts: 11
Joined: 19 Sep 2022, 14:41

Improve the speed of pasting from excel

Post by Astroboy12 » 28 Sep 2022, 06:34

Hi everyone. As you know I am a newbie. I have read everyone's posts and finished my code but there is a problem. That is when Copying the code into the array into PASTE, its speed is quite slow. Is there any way it can do it instantly like I ctrl v. Here is my code

Code: Select all

#IfWinActive, ahk_class XLMAIN
!c::
try
{

    Values := []
    for Cell, in ComObjActive("Excel.Application").Selection
        Values.Push(Cell.Text) ; 
}
catch
{
    clipsave := ClipboardAll ; Mảng Save 
    Clipboard := "" ; Clipboard data
    send ^c
    ClipWait, 2
    clipcopy := Clipboard
    Clipboard := clipsave
    if (clipcopy)
        Values := StrSplit(clipcopy, "`t", "`r`n")
    clipsave := clipcopy := "" ; gán trường clipboard vào 
}
if !(Values.length())
    MsgBox, 48, No Selection, No cells copied!
return
#If
 
!v::
Loop{
if (Values.length())
{
SendInput, % Values.RemoveAt(1); THIS IS INPUTDATA WHEN PASTE IS SLOW 
sleep 100
send {tab}			
SendInput, % Values.RemoveAt(1); THIS IS INPUTDATA WHEN PASTE IS SLOW 
sleep 100
send {tab 4}
sleep 500
send {Enter}
sleep 500
send {tab 5}
sleep 500
}
else
{
    MsgBox, 48, End of Range, End of Data. ; Kết thúc dòng hiện thông báo
    Values := ""
	break
}
}
return
Here is result when i paste data. It seems to be running in slow motion, making my next actions incorrect
https://youtube.com/shorts/F1x5XblKan4?feature=share

Thank you guy !

User avatar
boiler
Posts: 16705
Joined: 21 Dec 2014, 02:44

Re: Improve the speed of pasting from excel

Post by boiler » 28 Sep 2022, 06:55

Instead of SendInput, assign the text to the clipboard and then Send, ^v. It will paste as fast as as if you use Ctrl+v paste because that’s what it’s actually doing.

However, you need to pause for a bit before you assign something else to the clipboard after you send ^v or else it will overwrite it before Windows has a chance to execute the paste and it will send the wrong thing.

Astroboy12
Posts: 11
Joined: 19 Sep 2022, 14:41

Re: Improve the speed of pasting from excel

Post by Astroboy12 » 28 Sep 2022, 11:13

boiler wrote:
28 Sep 2022, 06:55
Instead of SendInput, assign the text to the clipboard and then Send, ^v. It will paste as fast as as if you use Ctrl+v paste because that’s what it’s actually doing.

However, you need to pause for a bit before you assign something else to the clipboard after you send ^v or else it will overwrite it before Windows has a chance to execute the paste and it will send the wrong thing.
Ok I got it. Thanks @boiler :) . Has my above code optimized the process or is there still a redundant step? Check it out for me if you have some free time

User avatar
boiler
Posts: 16705
Joined: 21 Dec 2014, 02:44

Re: Improve the speed of pasting from excel

Post by boiler » 28 Sep 2022, 11:39

I can't go through it in detail right now. I might be able to later if someone else hasn't provided feedback before then.

Astroboy12
Posts: 11
Joined: 19 Sep 2022, 14:41

Re: Improve the speed of pasting from excel

Post by Astroboy12 » 28 Sep 2022, 11:45

boiler wrote:
28 Sep 2022, 11:39
I can't go through it in detail right now. I might be able to later if someone else hasn't provided feedback before then.

I really appreciate your enthusiasm. Thank you !

User avatar
flyingDman
Posts: 2776
Joined: 29 Sep 2013, 19:01

Re: Improve the speed of pasting from excel

Post by flyingDman » 28 Sep 2022, 12:45

@Astroboy12 you have several sleeps totaling 1.7 seconds in each loop. So it pastes roughly 1 item every 2 seconds or 30 items a minute. Yes, that's slow. Remove the sleeps and it will fly...
14.3 & 1.3.7

Astroboy12
Posts: 11
Joined: 19 Sep 2022, 14:41

Re: Improve the speed of pasting from excel

Post by Astroboy12 » 04 Oct 2022, 02:39

flyingDman wrote:
28 Sep 2022, 12:45
@Astroboy12 you have several sleeps totaling 1.7 seconds in each loop. So it pastes roughly 1 item every 2 seconds or 30 items a minute. Yes, that's slow. Remove the sleeps and it will fly...
Sure FlyingDman. I will Remove the sleeps what you said. It will stuck in SENDINPUT so i will try other code to send ^c to clipboard and send^v from clipboard to each one by one. Thank you! Hope you have a nice day :D

Astroboy12
Posts: 11
Joined: 19 Sep 2022, 14:41

Re: Improve the speed of pasting from excel

Post by Astroboy12 » 04 Oct 2022, 16:16

boiler wrote:
28 Sep 2022, 06:55
Instead of SendInput, assign the text to the clipboard and then Send, ^v. It will paste as fast as as if you use Ctrl+v paste because that’s what it’s actually doing.

However, you need to pause for a bit before you assign something else to the clipboard after you send ^v or else it will overwrite it before Windows has a chance to execute the paste and it will send the wrong thing.
Hi Boiler,

One more question. How can I copy an array of data from excel data and then send ^v values one by one can you tell me how? . Currently I am successful with the above code with paste values one by one = sendinput but when passing send ^v when I copy a clipboard array send ^v it will go all the data I have when I copy

Thank you

User avatar
boiler
Posts: 16705
Joined: 21 Dec 2014, 02:44

Re: Improve the speed of pasting from excel

Post by boiler » 04 Oct 2022, 16:37

Not sure what to tell you. Only have the data in the clipboard that you want to paste at that time. If you have all the data in there at the same time, of course it's going to paste it all at once.

User avatar
flyingDman
Posts: 2776
Joined: 29 Sep 2013, 19:01

Re: Improve the speed of pasting from excel  Topic is solved

Post by flyingDman » 04 Oct 2022, 17:30

Try:

Code: Select all

arr := []
for cell in ComObjActive("Excel.Application").selection
	arr.push(cell.text)
return

#\::
clipboard := ""
clipboard := arr.RemoveAt(1)
clipwait,0
send ^v
;sleep, 100    ; might be needed 
return
14.3 & 1.3.7

Astroboy12
Posts: 11
Joined: 19 Sep 2022, 14:41

Re: Improve the speed of pasting from excel

Post by Astroboy12 » 06 Oct 2022, 11:31

flyingDman wrote:
04 Oct 2022, 17:30
Try:

Code: Select all

arr := []
for cell in ComObjActive("Excel.Application").selection
	arr.push(cell.text)
return

#\::
clipboard := ""
clipboard := arr.RemoveAt(1)
clipwait,0
send ^v
;sleep, 100    ; might be needed 
return

Sorry for the late response. Your code completely meets what I'm talking about thanks to @flyingDman and @Boiler. Thanks to both of you, I was able to learn a lot from Autohotkey

Post Reply

Return to “Ask for Help (v1)”