Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Dummy variable in macros

I am using a macro to load several text files that have lots of saved data
in them. It is way to time consuming to load each file alone, as there are a
lot of them. My problem lies in the fact the files names are never the same
for each data set, as we have a random number generator to ensure our test
data is statistically correct. This leaves me with a bunch of files I need
to load in order, but each of them has a random number in the file name. Is
there any way to run a macro and load files that can overlook certain
characters in the file name? Example: my file names are P015 and P026. I
want to be able to overlook the 01 and 02 part and just tell Exceel to see
P**5 and P**6. Is there a way to do this? Or an alrernative way to load
several files that have random numbers in the file names - while still
needing them to be in order. I am using Excel Prof. 2003. Any help is
greatly appreciated...
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Dummy variable in macros

Are all the files in one folder?

If yes:

Option Explicit
Sub testme01()

Dim myNames() As String
Dim fCtr As Long
Dim myFile As String
Dim myPath As String
Dim TempWkbk As Workbook

'change the folder here
myPath = "C:\my documents\excel\test\"
If myPath = "" Then Exit Sub
If Right(myPath, 1) < "\" Then
myPath = myPath & "\"
End If

myFile = ""
On Error Resume Next
myFile = Dir(myPath & "*.txt")
On Error GoTo 0
If myFile = "" Then
MsgBox "no files found"
Exit Sub
End If

'get the list of files
fCtr = 0
Do While myFile < ""
If LCase(myFile) Like LCase("p##5.txt") _
Or LCase(myFile) Like LCase("p##6.txt") Then
fCtr = fCtr + 1
ReDim Preserve myNames(1 To fCtr)
myNames(fCtr) = myFile
End If
myFile = Dir()
Loop

If fCtr 0 Then
For fCtr = LBound(myNames) To UBound(myNames)
Workbooks.OpenText Filename:=myPath & myNames(fCtr)
Set TempWkbk = ActiveWorkbook
'do your stuff
TempWkbk.Close savechanges:=False
Next fCtr
End If

End Sub


BWimer wrote:

I am using a macro to load several text files that have lots of saved data
in them. It is way to time consuming to load each file alone, as there are a
lot of them. My problem lies in the fact the files names are never the same
for each data set, as we have a random number generator to ensure our test
data is statistically correct. This leaves me with a bunch of files I need
to load in order, but each of them has a random number in the file name. Is
there any way to run a macro and load files that can overlook certain
characters in the file name? Example: my file names are P015 and P026. I
want to be able to overlook the 01 and 02 part and just tell Exceel to see
P**5 and P**6. Is there a way to do this? Or an alrernative way to load
several files that have random numbers in the file names - while still
needing them to be in order. I am using Excel Prof. 2003. Any help is
greatly appreciated...


--

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
Writing Macros - Dummy Guide Kevin Excel Discussion (Misc queries) 1 September 27th 07 01:49 PM
Macros with variable data jeannie v Excel Worksheet Functions 2 June 17th 07 10:20 PM
Dummy Variables rz-illini85 Excel Discussion (Misc queries) 4 December 6th 06 11:45 AM
Excel Dummy - Please Help! Ed Excel Discussion (Misc queries) 9 November 13th 05 07:59 PM
Question for dummy Yuri Weinstein \(HotMail\) New Users to Excel 9 June 17th 05 04:34 AM


All times are GMT +1. The time now is 01:37 AM.

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

About Us

"It's about Microsoft Excel"