reading CSV cells and pasting it into chrome browser

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
rolo6464
Posts: 23
Joined: 13 Apr 2021, 17:57

reading CSV cells and pasting it into chrome browser

Post by rolo6464 » 13 Apr 2021, 18:03

Hi guys,

I have a need for a super simple script but not sure how its done. Basically I have a csv file and it needs to copy the cells in column W, then go to chrome and past the url that was in the cell, then close the tab and that's it. But I need it to do it for all the cells in column W, one at a time until I reach blank cells. So basically:


start loop
copy cell W1, go to chrome and paste, then close tab
copy cell W2, go to chrome and paste, then close tab
copy cell W3, go to chrome and paste, then close tab
copy cell W4, go to chrome and paste, then close tab

repeat until the cell in Wxxx is a blank, then stop the loop (if this part is too hard I can just specify the number of loops required as I would know the information before running the code by counting the rows)

end loop




Is there anyone that can guide me in the right direction

So far I only know how to do the run chrome and paste and close tab part.

Thanks for your help

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

Re: reading CSV cells and pasting it into chrome browser

Post by mikeyww » 13 Apr 2021, 19:00

Code: Select all

file = %A_ScriptDir%\test.csv
If !FileExist(file) {
 MsgBox, 48, Error, File not found. Aborting.`n`n%file%
 Return
} Else FileRead, ttext, %file%
If !WinExist(wTitle := "ahk_exe chrome.exe") {
 Run, chrome.exe
 WinWaitActive, %wTitle%,, 10
 If ErrorLevel {
  MsgBox, 48, Error, An error occurred while waiting for Chrome. Aborting.
  Return
 }
} Else WinActivate
Loop, Read, %file%
{ Loop, Parse, A_LoopReadLine, CSV
  { If (A_Index < 23)
     Continue
    If (A_LoopField = "")
     Return
    Send %A_LoopField%^w
    Sleep, 100
    Break
  }
}

rolo6464
Posts: 23
Joined: 13 Apr 2021, 17:57

Re: reading CSV cells and pasting it into chrome browser

Post by rolo6464 » 13 Apr 2021, 20:44

mikeyww wrote:
13 Apr 2021, 19:00

Thanks so much for your code! I only had to do some minor tweaks to get exactly what I needed.

rolo6464
Posts: 23
Joined: 13 Apr 2021, 17:57

Re: reading CSV cells and pasting it into chrome browser

Post by rolo6464 » 14 Apr 2021, 13:28

Hey sorry to bring this up again,

I did come across one issue that is affecting me running this code.

You know how the code is currently designed to stop when it detects a blank cell.

Is it possible for the code to start to run and if it detects a "0" in that column it reads to simply skip over all "0" cells until it hits a populated cell, then run the code and stop again when it hits the blank cell again like it currently does.

The reason being is I have thousands of cells of rows and I need to run the code in batches. So I would delete the first couple hundred cells and replace it with the number 1, leaving a few hundred populated that I need to run, then delete the rest of the cells so it only runs it in that section for that period, if that makes sense.

Just not sure how to do the if = 1 then skip to next row part.

Thank you

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

Re: reading CSV cells and pasting it into chrome browser

Post by mikeyww » 14 Apr 2021, 15:41

Maybe like this:

Code: Select all

started := False
Loop, Read, %file%
{ Loop, Parse, A_LoopReadLine, CSV
  { If (A_Index != 23)
     Continue
    If A_LoopField {
     Send %A_LoopField%^w
     Sleep, 100
     started := True
    } Else If started
       Return
  }
}

rolo6464
Posts: 23
Joined: 13 Apr 2021, 17:57

Re: reading CSV cells and pasting it into chrome browser

Post by rolo6464 » 14 Apr 2021, 18:44

Hey, thanks for your reply.

I don't understand where it reads the part about it being a "0" and skipping to the next line:

This is the code I have:

Code: Select all

file = C:\test.csv
If !FileExist(file) {
 MsgBox, 48, Error, File not found. Aborting.`n`n%file%
 Return
} Else FileRead, ttext, %file%
If !WinExist(wTitle := "ahk_exe chrome.exe") {
 Run, chrome.exe
 WinWaitActive, %wTitle%,, 5
sleep, 1500
} Else WinActivate
WinActivate
Loop, Read, %file%
{ Loop, Parse, A_LoopReadLine, CSV
  { If (A_Index < 23)
     Continue
    If (A_LoopField = "")
     Return
    Send ^t
    Sleep, 500
    Send %A_LoopField%
    Sleep, 1000
    Send {enter}
    Sleep, 4000
    Send ^w
    Break
  }
}
Alternatively can we not assign a 1 to skip that row and a 0 to end the loop? I could easily just add 1's and 0's where they belong for example.

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

Re: reading CSV cells and pasting it into chrome browser

Post by mikeyww » 14 Apr 2021, 20:42

You tried my script?

rolo6464
Posts: 23
Joined: 13 Apr 2021, 17:57

Re: reading CSV cells and pasting it into chrome browser

Post by rolo6464 » 15 Apr 2021, 00:25

wow that worked, took a while to integrate it into my script but also suprised there was no "0" anywhere in the script yet it knew the interpret only that number. well shows how much i know, thanks a lot for your help with this!

Post Reply

Return to “Ask for Help (v1)”