AutoHotkey Community

It is currently May 26th, 2012, 8:13 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 39 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Copy a list from Excel
PostPosted: June 30th, 2004, 2:34 pm 
Offline

Joined: June 30th, 2004, 2:00 pm
Posts: 3
Hi,
I'm trying to copy a list of numbers, one by one, from Excel to an accounts package.
I am only using AutoHotKey a few hours so am a bit lost..
I have used the Window Spy to find my starting cell, and can copy the cell using
MouseClick, left, 87, 164
Sleep, 100
Send, {CTRLDOWN}c{CTRLUP}

but can't get back to the starting position to move one cell down...I belive I could then loop this if it worked...
I have tried MouseMove, but get syntax errors....any ideas ?
Thanks...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 30th, 2004, 2:57 pm 
What about to create/write a plain text file following the standard *.csv (comma separated value) syntax ?

var1,var2,var3,var4,...

a) parse the (MyExcelFile.csv) file directly using a loop
b) pipe the content of each single cell into whatever destination file

if that sounds to complex give us a line of your source file and a sample line of the format how it should look like in the destination file, and let's see how we can make it ...


Report this post
Top
  
Reply with quote  
 Post subject: Copy a list from Excel
PostPosted: June 30th, 2004, 4:18 pm 
Offline

Joined: June 30th, 2004, 2:00 pm
Posts: 3
That sounds like it could work....but having difficulty getting list of numbers from Excel format to csv format...even when i save as .csv, they still look like this
987374
987375
987376

as opposed to 987374, 987375, 987376 etc.

any thoughts...I'm not a programmer, just a lowly accounts person !


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Coping Excel Cells
PostPosted: June 30th, 2004, 6:41 pm 
I cannot help you directly, but have had great failure with coping Excel cells, until I realized you cannot just copy, you get other things as well.

This is my solution and works perfectly, but there must be a better way.

I have this as a gosub to copyv. after putting the cursor in a cell.

;COPY VARIABLES, USING EXCEL F2 AS A METHOD TO STRIP OUT THE RETURN AT THE END OF EACH EXCEL CELL

COPYV:

Send, {F2}{HOME}{SHIFTDOWN}{END}{SHIFTUP}{CTRLDOWN}c{CTRLUP}{TAB}

RETURN


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 30th, 2004, 7:02 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
In Excel, it's probably best to avoid navigating with the mouse. Instead, use keystrokes. For example:

Send, ^{Home} ; Go to Row 1 Col 1
Send, ^{End} ; Go to lower-right cell
Send, ^{PgUp 9}^{PgDn 2} ; Go to the 3rd worksheet or tab.

; Jump directly to a specific cell:
Send, ^g
WinWaitActive, Go To
Send, B18{enter}

Also, the following is a more reliable way to copy:
clipboard = ; start off empty
Send, ^c
ClipWait
; At this point, you can continue with confidence, knowing something has been copied to the clipboard.

If needed, to remove the CRLF from the end of the copied cell (before pasting it), you can also use this method:
StringReplace, clipboard, clipboard, `r`n

If you have a large quantity of data to copy over (perhaps 100 rows or more), it might be better to use a parsing loop. If that is the case, we can help you with that.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 2nd, 2004, 5:33 pm 
Offline

Joined: June 30th, 2004, 2:00 pm
Posts: 3
First of all, allow me to say thanks for all the help; it is much appreciated.
The Parsing Loop sounds the best, as I have around 3000 rows of data -(and that's just this week). I need one value copied to an accounts package (different window) and then to press ok in this window, then to come back to Excel and take the next value and do the same....3000 times...
Imagine if you had a list of names and you had to enter them into a Database, but only one at a time, and to validate each one (by pressing ok)
Data looks something like this:
987374
987375
987376
987377
987499

Each of these has to be entered into the system one by one.

I know you may ask why I can't just import them directly using Access \ SQL or similar, and it's because I am not entering these numbers into a Table as such. These numbers are being entered as values of a programme which will then perform a job on these numbers.

Example - when I launch this programme, it asks me "What numbers do you wish to operate on ?" and I have to enter the 1st number, and press Ok, enter the 2nd number, press ok....etc. Then the programme performs an operation on all the numbers I have just entered.
Hope that explains a bit more clearly.

Thanks a lot for any new ideas ....!
:)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 2nd, 2004, 8:16 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
If you haven't already, be sure to read the quick-start tutorial at http://www.autohotkey.com/docs/Tutorial.htm -- it explains how to send keystrokes, activate windows, etc.

For the job you described, it sounds like a cycle of Copy - ClipWait - WinActivate - Paste will work. You can get more sophisticated (and possibly speed up the process) by using ControlSetText (which might possibly avoid the need to activate the target window). But if speed isn't important, you can probably stick to WinActivate and the Send command.

If you need something more complex to automate this process, feel free to ask more specific questions (which tend to generate more useful answers).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 4th, 2004, 3:00 pm 
JOXER

I'm trying to do a similar thing but I you are ahead of me, can you let me know what you have got already?

Thanks

Mike


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2004, 1:37 am 
Well, I suprised myself - spent an hour on it and managed to get something working. This copies the contents of column A in excel into word one cell at a time (make sure that both word and excel are open an they are Document/Book 1)

Code:
; triggered by pressing the windows key and the X key

#x::

; jump to excel

   WinActivate Microsoft Excel - Book1

; first cell

Send, ^{Home}


;  keep looping

Loop,
{

; copy the current cell

  clipboard = ;
  Send, ^c
  ClipWait
  StringReplace, clipboard, clipboard, `r`n

; if empty cell then stop

  if clipboard =
    break

; jump to word

   WinActivate Microsoft Word - Document1

; paste in the clipboard contents

  Send, ^v

; for word add a return at the end to get a new line
 
  Send, {Return}

; jump back to excel

   WinActivate Microsoft Excel - Book1

; go down to the next cell in excel
 
  send, {Down}
}


For your application, just replace the word WinActivate with the app you want and make sure you process the screen.

Mike


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2004, 7:21 pm 
That worked brilliantly - thanks a lot for all the help and aplologies too for non specific questions - this has saved me many hours plugging away..
Cheers
Joxer
:D


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2004, 8:22 pm 
I only found the download yesterday. To start with it looked daunting, the tuturial starts at too an advanced stage - it assumes you know too much. But the bit that is actually missing is only a tiny bit to explain how it fits together. If I get chance I'll write up that bit before I get too proficient (which I will given how usefull it is) and get to assume everyone knows more than they do. It is the least I can do for such a brilliant tool.

Mike


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2004, 8:28 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Quote:
the tuturial starts at too an advanced stage - it assumes you know too much. But the bit that is actually missing is only a tiny bit to explain how it fits together

I value your perspective on this. Often myself and others who have scripted a lot don't realize what things look like to someone just learning. I'll try to incorporate whatever ideas you offer into the tutorial. Thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 27th, 2008, 8:57 pm 
Offline

Joined: March 5th, 2007, 8:51 pm
Posts: 20
Location: Erie, PA
I use AHK and Excel all day for my profession (pricing analyst for a large retail computer site) and I have some pointers that might help/clear some stuff up. Or not, just my $.02 :)

Code:
; jump to excel

   WinActivate Microsoft Excel - Book1

It's ok to change this to:
Code:
WinActivate Microsoft Excel

This way the title doesn't need to say "Book1" so you can use it in any Excel document. But for more preciseness, use this:
Code:
IfWinExist ahk_class XLMAIN
   {
      WinActivate
      WinWaitActive ahk_class XLMAIN
   }
   else
   {
      msgbox Excel not running.`r`nStopping command.
      return 1
   }

The above code uses Microsoft Excel's class name, instead of it's Window Title text to activate it.

The same thing can be used with Word as well so instead of using:
Code:
WinActivate Microsoft Word - Document1

you can use:
Code:
WinActivate Microsoft Word

to use word document's not named "Document1".

When outputting the contents of the clipboard, I've found that using:
Code:
SendInput %clipboard%

is much faster than sending the keystroke to paste it:
Code:
Send, ^v


If you're going to add a return after outputting a variable like this:
Code:
; for word add a return at the end to get a new line 

  Send, {Return}

leaving the CRLF (`r`n) on the end of the data copied from Excel will output a return automatically so the Sending of a {Return} character is unnecessary. Although, I admit, sometimes I like to code scripts the less efficient way sometimes just so when I come back to the code later on, I can see that there's a {Return} getting sent for a reason. :wink:

Also, I think Pallie forgot a
Code:
Return
after his loop ending.

Pallie wrote:
To start with it looked daunting, the tuturial starts at too an advanced stage - it assumes you know too much. But the bit that is actually missing is only a tiny bit to explain how it fits together.

I think you'll have this with any scripting language, and yes, sometimes it can be frustrating trying to learn something new from scratch. :wink:
Just remember, most all programming languages (AHK included) use different commands and syntax to do everything. This is why it's important to understand the act of programming, what it is, and how to do it. It is at that point that you can start to learn a new programming language, such as AHK.
Here are some common questions about programming answered:
http://www.guidetoprogramming.com/main_site_conent/site_content/

_________________
My AutoHotKey.com username has changed to GeekyAdam


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 27th, 2008, 9:38 pm 
@ adamisageek/JOXER
Check out [ADO (by Sean)]. It offers a more sophisticated way to extract/inject data into an Excel sheet.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 27th, 2008, 9:45 pm 
Offline

Joined: March 5th, 2007, 8:51 pm
Posts: 20
Location: Erie, PA
I looked into that a little BoBo, today actually. But it seems more complicated than the simple functions I use in my script.

Granted, it could be a lot more precise/efficient but for now, I'm going to have to wait...it seems like I'll have to learn another entirely different programming language to use the ADO stuff.

I probably will though eventually, I have some ideas that will make my job much much easier, I just need to do some research first and start the huge overhaul to my code. :roll:

_________________
My AutoHotKey.com username has changed to GeekyAdam


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 39 posts ]  Go to page 1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, poserpro, sjc1000, Tilter_of_Windmills and 57 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group