 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
totalmig
Joined: 22 Jul 2008 Posts: 122
|
Posted: Wed Jul 23, 2008 10:43 am Post subject: |
|
|
Hi.
I am trying to do something somewhat similiar to this.
Would it be possible to make a script that did the following:
I enter a street name and push enter
Then the script goes into an excel file and checks if the street name is the same as cell b1, if not it moves onto b2 an so on. Until it finds a match, when it finds a match i would like it to copy the information in that cell and the 4 cells to right into different variables, which i could then use.
I know the basics, just not sure whether or not extracting data from excel is possible. Thanks for your time.
Is this possible? |
|
| Back to top |
|
 |
GeekyAdam
Joined: 07 May 2008 Posts: 4 Location: Erie, PA
|
Posted: Wed Jul 23, 2008 7:27 pm Post subject: |
|
|
| totalmig wrote: | Hi.
I am trying to do something somewhat similiar to this.
Would it be possible to make a script that did the following:
I enter a street name and push enter
Then the script goes into an excel file and checks if the street name is the same as cell b1, if not it moves onto b2 an so on. Until it finds a match, when it finds a match i would like it to copy the information in that cell and the 4 cells to right into different variables, which i could then use.
I know the basics, just not sure whether or not extracting data from excel is possible. Thanks for your time.
Is this possible? |
Without using ADO or COM commands, I don't know of a way to go to a certain cell using only AHK commands (by all means correct me if I'm wrong anyone). So I'll assume you have Excel open and focus is on the B1 cell.
Here's a rough draft:
| Code: | InputBox streetname, Street Name, Please enter a street name
WinActivate ahk_class XLMAIN
WinWaitActive ahk_class XLMAIN
loop
{
clipboard =
Send ^c
ClipWait
StringReplace clipboard, clipboard, `r`n, , All
if (clipboard = streetname)
break ;match found
if (clipboard = "")
return 1 ;no match found (end of list in "B" column)
Send {DOWN}
}
loop 5
{
infoarray%A_Index% := clipboard
Send {RIGHT}
clipboard =
Send ^c
ClipWait
StringReplace clipboard, clipboard, `r`n, , All
}
MsgBox , Results,
(LTrim
1st cell: %infoarray1%
2st cell: %infoarray2%
3st cell: %infoarray3%
4st cell: %infoarray4%
5st cell: %infoarray5%
) |
note: done quickly while at work...didn't test...hope it holds up  |
|
| Back to top |
|
 |
Hasso
Joined: 23 Mar 2005 Posts: 158 Location: Germany
|
Posted: Mon Jul 28, 2008 9:10 am Post subject: |
|
|
I tried to solve the initial problem and ended with the following script (works, if the numbers to copy are in a column with no empty cells between them and the cell containing the first value is activated):
| Code: | SetTitleMatchMode, 2
#IfWinActive, Excel
+#u:: ;hotkey Shift+Windows+u - change to your needs
clipboard=
send,+^{DOWN}^c ;copy the whole range of values you want to export
ClipWait
values:=clipboard
send, {ESC}{HOME}
StringSplit, numbers, values, `n ;splits the string with the values to an array (numbers)
WinActivate, Word ;or where ever you want to paste the values
WinWaitActive, Word
Loop, %numbers0% ;%numbers0% is the total of values in your array
{
pastevalue:=numbers%A_INDEX%
send, %pastevalue%
}
return
return
#IfWinActive, Excel |
Tested. _________________ Hasso
Programmers don't die, they GOSUB without RETURN |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|