reverberation wrote: ↑21 Mar 2019, 19:46
I have the following script, which allows me to do an image search in Google for any highlighted cell.
What I want to achieve is, IF I ever highlight 5 cells at a time, it will extract the words for each cell, open new tab in Chrome to search for that term in Google images, instead of having to hit Ctrl+Win+Q for every cell that I want to search in Google. Any idea how I can do that please?
Code: Select all
; Ctrl Win Q to run Google Images
$^#Q::
Send, ^c
Sleep 50
parameter = C:\Program Files (x86)\Google\Chrome\Application\chrome.exe https://www.google.com.sg/search?q="%clipboard%"&hl=en&gbv=2&tbs=isz:lt,islt:vga&tbm=isch&source=lnt&sa=X&ei=9UXAT-HlDofxrQfcg_XiCQ&ved=0CCwQpwUoBA&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.,cf.osb&biw=1366&bih=677&cad=h
Run %parameter%
Return
Hello,
This is a much more direct way of taking the contents in your cells and running a Google Image Search by using COM. You can select more than 5 cells with this method if you want- you could select 10,000 or just 1 cell if wanted, any number of cells will work.
Well... actually Google has a limit and AHK won't run the string if it's too long
As far as searches, you can conduct the searches for 2048 characters with spaces but if you are searching for any subsequent keyword then google would limit the search till 32 words.
With this method you can also select cells that are not adjacent to one another (like with ctrl+left click). It will create the query in the order that you select the cells.
Code: Select all
$^#Q::
Xl := ComObjActive("Excel.Application")
For SelectedCell in Xl.Selection
SelectedCells .= SelectedCell.Value "+"
Query := StrReplace(SelectedCells, A_Space, "+")
, GoogleImageSearch := "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe "
. "https://www.google.com.sg/search?q=" Query "&hl=en&gbv=2&tbs=isz:lt,islt:vga&"
. "tbm=isch&source=lnt&sa=X&ei=9UXAT-HlDofxrQfcg_XiCQ&ved=0CCwQpwUoBA&"
. "bav=on.2,or.r_gc.r_pw.r_cp.r_qf.,cf.osb&biw=1366&bih=677&cad=h"
Run % GoogleImageSearch
return
LMK how that works for you!
EDIT: changed
For SelectedCell, Value in Xl.Selection to
For SelectedCell in Xl.Selection as it is unnecessary.