Page 1 of 1

Improve the speed of pasting from excel

Posted: 28 Sep 2022, 06:34
by Astroboy12
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 !

Re: Improve the speed of pasting from excel

Posted: 28 Sep 2022, 06:55
by boiler
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.

Re: Improve the speed of pasting from excel

Posted: 28 Sep 2022, 11:13
by Astroboy12
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

Re: Improve the speed of pasting from excel

Posted: 28 Sep 2022, 11:39
by boiler
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.

Re: Improve the speed of pasting from excel

Posted: 28 Sep 2022, 11:45
by Astroboy12
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 !

Re: Improve the speed of pasting from excel

Posted: 28 Sep 2022, 12:45
by flyingDman
@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...

Re: Improve the speed of pasting from excel

Posted: 04 Oct 2022, 02:39
by Astroboy12
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

Re: Improve the speed of pasting from excel

Posted: 04 Oct 2022, 16:16
by Astroboy12
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

Re: Improve the speed of pasting from excel

Posted: 04 Oct 2022, 16:37
by boiler
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.

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

Posted: 04 Oct 2022, 17:30
by flyingDman
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

Re: Improve the speed of pasting from excel

Posted: 06 Oct 2022, 11:31
by Astroboy12
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