AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Copy a list from Excel
Goto page Previous  1, 2
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
totalmig



Joined: 22 Jul 2008
Posts: 122

PostPosted: Wed Jul 23, 2008 10:43 am    Post subject: Reply with quote

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
View user's profile Send private message
GeekyAdam



Joined: 07 May 2008
Posts: 4
Location: Erie, PA

PostPosted: Wed Jul 23, 2008 7:27 pm    Post subject: Reply with quote

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 Rolling Eyes
Back to top
View user's profile Send private message Send e-mail AIM Address
Hasso



Joined: 23 Mar 2005
Posts: 158
Location: Germany

PostPosted: Mon Jul 28, 2008 9:10 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group