AutoHotkey Community

It is currently May 26th, 2012, 11:52 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Lost outside the loop
PostPosted: November 12th, 2009, 4:53 pm 
Offline

Joined: November 11th, 2009, 12:53 am
Posts: 9
Location: Australia
This code almost does what I want, but I'm a little lost with the loop command to make it all happen again,
Specifically
1. Open Excel, (do this once)
2. Open Text file from a folder, Copy three lines respectively into cells A1, B1, C1
3. Close Text file, Open next text file in folder, copy the three lines.
4. continue until there are no text files left in the folder.

Text files named sequentially: 001xxxxxxxxx, 002xxxxxxxx, 003xxxxxxx etc.


Code:
; AutoHotkey Version: 1.0.48.05
; Language:       English
; Platform:       Windows XP Professional 5.1 SP3
; Author:         C. Waring
;
; Script Function: To Make one New Excel File and to copy all results (from mulitply .txt) made in program Mark to rows in the Excel sheet.
;

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

FileSelectFile, Results, 3, C:\Documents and Settings\gseuser\Desktop\Bootstrap\,Name New Results File ,*xls
Run, %Results%
WinActivate, ahk_class XLMAIN
Send, ^{Home} ; Go to Row 1 Col 1

clipboard = ; start off empty

FileSelectFile, File,,,Select first .txt file,*.txt

Loop,%File%, 0, 0

{
File = %A_LoopFileFullPath%
Run, %File%
Loop, Read, %File%,
FileReadLine, Name, %File%, 8
ControlSend, XLDESK1, %Name%, ahk_class XLMAIN
WinActivate, ahk_class XLMAIN
Send {tab}
clipboard = ; start off empty

WinActivate, ahk_class Notepad
WinWait, ahk_class Notepad
Loop, Read, %File%,
If A_LoopReadLine contains Model=
{
  StringReplace, var, A_LoopReadLine, {, +[, All ; "Shift + [") = {
  StringReplace, var, var, }, +], All
  ControlSend, XLDESK1, %var%, ahk_class XLMAIN
}
WinActivate, ahk_class XLMAIN
Send {tab}

WinActivate, ahk_class Notepad
WinWait, ahk_class Notepad
Loop, Read, %File%,
If A_LoopReadLine contains 1     1
ControlSend, XLDESK1, %A_LoopReadLine%, ahk_class XLMAIN
WinActivate, ahk_class XLMAIN
Send {tab}
Sleep, 100
Send {enter}
Sleep, 100
WinClose, ahk_class Notepad
}

_________________
Learning on the fly


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2009, 4:58 pm 
Offline

Joined: November 14th, 2007, 2:47 pm
Posts: 335
Location: London, England
I would append all of the data into one csv file.

Then open that up in Excel, and save as a different format if needed.

Loop through your files, but rather than paste them into excel, use the FileAppend command to create your Excel file.

Far more elegant, and doesnt bombard the screen with key movements. :)

Need anymore help just ask.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: hyper_, Leef_me, patgenn123, Pulover, rbrtryn, tidbit, XstatyK and 19 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