neiltharvey
New Member
- Joined
- Mar 9, 2010
- Messages
- 2
Hi all. This is my first thread, and hope someone can help me. I know this question has been posted before, and I've tried to follow the solutions, but just get very confused! I'm quite a novice to Excel, and have taken on a spreadsheet that produces MI reports for a customer, and I've just upgraded to 2007, and find that the Application. Filesearch isn't supported. After a bit of hunting (told you I'm a novice), I found the code:
'Capture Directory name and file type
With Application.FileSearch
.NewSearch
.LookIn = txtDirectory
.SearchSubFolders = True
.FileName = txtFileName
.Execute
TotalFiles = .FoundFiles.count
If (TotalFiles > MAX_FILES) Then
MsgBox "Max number of files exceded. Max is " + CStr(MAX_FILES)
GoTo Exit_Get_Data
End If
count = 1
Do While count < TotalFiles + 1
CurrentFile = .FoundFiles(count)
'Remove path (for stats ONLY)
FileLength = Len(CurrentFile)
FileLoc = InStrRev(CurrentFile, "\")
FileNameOnly = Right(CurrentFile, FileLength - FileLoc)
FilesList = FilesList & FileNameOnly & Chr(10)
'find where to paste
Sheets(REPORT_WORKSHEET).Select
R = 1
Do While Cells(R, 1) > ""
R = R + 1
Loop
StartAddress = "A" & R
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & CurrentFile, Destination:=Range(StartAddress))
.Name = CurrentFile
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = ","
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
count = count + 1
Loop
End With
Can some clever person somewhere out there tell me in idiot terms what I need to change in the above code to get it to work? Many thanks in anticapation, Neil Harvey
'Capture Directory name and file type
With Application.FileSearch
.NewSearch
.LookIn = txtDirectory
.SearchSubFolders = True
.FileName = txtFileName
.Execute
TotalFiles = .FoundFiles.count
If (TotalFiles > MAX_FILES) Then
MsgBox "Max number of files exceded. Max is " + CStr(MAX_FILES)
GoTo Exit_Get_Data
End If
count = 1
Do While count < TotalFiles + 1
CurrentFile = .FoundFiles(count)
'Remove path (for stats ONLY)
FileLength = Len(CurrentFile)
FileLoc = InStrRev(CurrentFile, "\")
FileNameOnly = Right(CurrentFile, FileLength - FileLoc)
FilesList = FilesList & FileNameOnly & Chr(10)
'find where to paste
Sheets(REPORT_WORKSHEET).Select
R = 1
Do While Cells(R, 1) > ""
R = R + 1
Loop
StartAddress = "A" & R
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & CurrentFile, Destination:=Range(StartAddress))
.Name = CurrentFile
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = ","
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
count = count + 1
Loop
End With
Can some clever person somewhere out there tell me in idiot terms what I need to change in the above code to get it to work? Many thanks in anticapation, Neil Harvey