Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Corben
 
Posts: n/a
Default opening multiple .txt files from multiple folders

At my work, we have about 10 computers that save data to a text file on a
daily basis. The file names that are created at the same, so we have to save
it to a different location on the network. Filenames are in date format ex:
03-15-06.txt

I'd like to be able to put the information together, and have been doing it
manually for a while now. Right now I open each file, copy the data, and then
create a seperate single .txt file with all the data for each day. I then
open the file in Excel and use Tab, Semicolon, and Colon as delimiters.

Does anyone know if a macro can be set up to look into the seperate folders,
and open each file, copying all the data into 1 worksheet?

If this can be done, or if anyone has any suggestions, I'd appreciate it.
Thanks,

I'm using Excel 2003
  #2   Report Post  
Posted to microsoft.public.excel.misc
Doug Kanter
 
Posts: n/a
Default opening multiple .txt files from multiple folders


"Corben" wrote in message
...
At my work, we have about 10 computers that save data to a text file on a
daily basis. The file names that are created at the same, so we have to
save
it to a different location on the network. Filenames are in date format
ex:
03-15-06.txt

I'd like to be able to put the information together, and have been doing
it
manually for a while now. Right now I open each file, copy the data, and
then
create a seperate single .txt file with all the data for each day. I then
open the file in Excel and use Tab, Semicolon, and Colon as delimiters.

Does anyone know if a macro can be set up to look into the seperate
folders,
and open each file, copying all the data into 1 worksheet?

If this can be done, or if anyone has any suggestions, I'd appreciate it.
Thanks,

I'm using Excel 2003



The answer is "yes".

Based on my own learning style, the best way to learn how is to record a
macro as you do the steps manually. But, don't use important files while
experimenting. Rename the text files first, and use a dummy Excel sheet, not
the one you need for business purposes. After recording the macro, open the
editor to inspect it, and with the help of a VBA book (from your local
library?), begin to understand how the macro performs each step.


  #3   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default opening multiple .txt files from multiple folders

Record a macro when you import the real text file. You'll get the layout of
each field (text, general, date, etc).

But then you could merge your recorded macro into something like:

Option Explicit
Sub testme()

Dim myFolders As Variant
Dim iCtr As Long
Dim myDate As Date
Dim TestStr As String
Dim myFileName As String
Dim NewWks As Worksheet
Dim DestCell As Range

myFolders = Array("C:\my documents\excel\", _
"c:\temp")

myDate = Application.InputBox(Prompt:="Please enter the date", _
Default:=Format(Date, "mmmm dd, yyyy"), Type:=1)

If myDate = 0 Then
Exit Sub
End If

If Year(myDate) < 2006 _
Or Year(myDate) 2010 Then
MsgBox "Please check your date"
Exit Sub
End If

Set NewWks = Worksheets.Add
Set DestCell = NewWks.Range("a1")

For iCtr = LBound(myFolders) To UBound(myFolders)
If Right(myFolders(iCtr), 1) < "\" Then
myFolders(iCtr) = myFolders(iCtr) & "\"
End If

myFileName = myFolders(iCtr) & Format(myDate, "mm-dd-yy") & ".txt"
TestStr = ""
On Error Resume Next
TestStr = Dir(myFileName)
If TestStr = "" Then
MsgBox myFileName & " Is missing!"
Else
Workbooks.OpenText Filename:=myFileName, _
Origin:=437, StartRow:=1, DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=True, _
Comma:=False, Space:=False, Other:=True, OtherChar:=":", _
FieldInfo:=Array(1, 1)

With ActiveSheet
.UsedRange.Copy _
Destination:=DestCell
.Parent.Close savechanges:=False
End With

With NewWks
Set DestCell _
= .Cells(.Cells.SpecialCells(xlCellTypeLastCell).Row + 1, "A")
End With

End If
Next iCtr

End Sub


If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm


Corben wrote:

At my work, we have about 10 computers that save data to a text file on a
daily basis. The file names that are created at the same, so we have to save
it to a different location on the network. Filenames are in date format ex:
03-15-06.txt

I'd like to be able to put the information together, and have been doing it
manually for a while now. Right now I open each file, copy the data, and then
create a seperate single .txt file with all the data for each day. I then
open the file in Excel and use Tab, Semicolon, and Colon as delimiters.

Does anyone know if a macro can be set up to look into the seperate folders,
and open each file, copying all the data into 1 worksheet?

If this can be done, or if anyone has any suggestions, I'd appreciate it.
Thanks,

I'm using Excel 2003


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
Corben
 
Posts: n/a
Default opening multiple .txt files from multiple folders

Thank you for this exmaple and the website link.
I've had some experience with macros, so with a little bit of testing I
should be able to get this working.



"Dave Peterson" wrote:

Record a macro when you import the real text file. You'll get the layout of
each field (text, general, date, etc).

But then you could merge your recorded macro into something like:

Option Explicit
Sub testme()

Dim myFolders As Variant
Dim iCtr As Long
Dim myDate As Date
Dim TestStr As String
Dim myFileName As String
Dim NewWks As Worksheet
Dim DestCell As Range

myFolders = Array("C:\my documents\excel\", _
"c:\temp")

myDate = Application.InputBox(Prompt:="Please enter the date", _
Default:=Format(Date, "mmmm dd, yyyy"), Type:=1)

If myDate = 0 Then
Exit Sub
End If

If Year(myDate) < 2006 _
Or Year(myDate) 2010 Then
MsgBox "Please check your date"
Exit Sub
End If

Set NewWks = Worksheets.Add
Set DestCell = NewWks.Range("a1")

For iCtr = LBound(myFolders) To UBound(myFolders)
If Right(myFolders(iCtr), 1) < "\" Then
myFolders(iCtr) = myFolders(iCtr) & "\"
End If

myFileName = myFolders(iCtr) & Format(myDate, "mm-dd-yy") & ".txt"
TestStr = ""
On Error Resume Next
TestStr = Dir(myFileName)
If TestStr = "" Then
MsgBox myFileName & " Is missing!"
Else
Workbooks.OpenText Filename:=myFileName, _
Origin:=437, StartRow:=1, DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=True, _
Comma:=False, Space:=False, Other:=True, OtherChar:=":", _
FieldInfo:=Array(1, 1)

With ActiveSheet
.UsedRange.Copy _
Destination:=DestCell
.Parent.Close savechanges:=False
End With

With NewWks
Set DestCell _
= .Cells(.Cells.SpecialCells(xlCellTypeLastCell).Row + 1, "A")
End With

End If
Next iCtr

End Sub


If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm


Corben wrote:

At my work, we have about 10 computers that save data to a text file on a
daily basis. The file names that are created at the same, so we have to save
it to a different location on the network. Filenames are in date format ex:
03-15-06.txt

I'd like to be able to put the information together, and have been doing it
manually for a while now. Right now I open each file, copy the data, and then
create a seperate single .txt file with all the data for each day. I then
open the file in Excel and use Tab, Semicolon, and Colon as delimiters.

Does anyone know if a macro can be set up to look into the seperate folders,
and open each file, copying all the data into 1 worksheet?

If this can be done, or if anyone has any suggestions, I'd appreciate it.
Thanks,

I'm using Excel 2003


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I get cell data in multiple Excel files into one summary fi 78degreesinHI Excel Worksheet Functions 4 August 29th 06 02:05 AM
Multiple Text files into one worksheet-need help [email protected] Excel Discussion (Misc queries) 2 January 21st 06 05:09 PM
Excel opening all files in root of C: when launching yarbrough2 Excel Discussion (Misc queries) 1 March 31st 05 12:08 AM
multiple text files URGENT tasha Excel Discussion (Misc queries) 1 December 19th 04 05:44 PM
importing multiple text files??? tashayu Excel Discussion (Misc queries) 0 December 19th 04 02:43 PM


All times are GMT +1. The time now is 10:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"