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 

Lost outside the loop

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Columbine



Joined: 10 Nov 2009
Posts: 9
Location: Australia

PostPosted: Thu Nov 12, 2009 3:53 pm    Post subject: Lost outside the loop Reply with quote

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
Back to top
View user's profile Send private message
doyle



Joined: 14 Nov 2007
Posts: 279
Location: London, England

PostPosted: Thu Nov 12, 2009 3:58 pm    Post subject: Reply with quote

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. Smile

Need anymore help just ask.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
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