Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Read Contents of text File into worksheet

I have a macro that steps through each folder and reports it's size. I need
to also have it Look for a project.inf file in each folder and if it exists
add the string to a cell on the current worksheet. This is the code that I
have so far. The code does not contain any attempt to open the project.inf
file yet.

Thanks

Steve

Sub FolderSizeToWorksheet(sfol As Variant)
Dim fso As New FileSystemObject
Dim fld As Folder
Dim tFld As Folder
'Dim sfol As String

Application.ScreenUpdating = False
'sfol = "N:\Database"
Set fld = fso.GetFolder(sfol)
i = 0
For Each tFld In fld.SubFolders
i = i + 1

Cells(i, 1).Value = tFld.Name
Cells(i, 2).Value = tFld.Size
Cells(i, 3).Value = Cells(i, 2) / 1024
Cells(i, 4).Value = tFld.DateCreated
Cells(i, 5).Value = tFld.DateLastModified
With Application.FileSearch
.NewSearch
.LookIn = tFld
.SearchSubFolders = False
.Filename = "Project.inf"

If .Execute() 0 Then
ReDim Preserve Myfiles(1 To .FoundFiles.Count)
Application.StatusBar = "Found Files: " & .FoundFiles.Count
For i = 1 To .FoundFiles.Count
Myfiles(i) = .FoundFiles(i)
Next i
Else
MsgBox "There were no files found"
Exit Sub
End If
End With

If tFld.Size < 200 Then
tFld.Delete True
Cells(i, 6).Value = "Deleted"
End If
Next

Application.ScreenUpdating = True
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Read Contents of text File into worksheet

Code seems to work. What are you asking?

why do you jump out of the sub the first time you hit a subdirectory where
no files are found?

--
Regards,
Tom Ogilvy

"Steve Roberts" wrote in message
...
I have a macro that steps through each folder and reports it's size. I

need
to also have it Look for a project.inf file in each folder and if it

exists
add the string to a cell on the current worksheet. This is the code that I
have so far. The code does not contain any attempt to open the project.inf
file yet.

Thanks

Steve

Sub FolderSizeToWorksheet(sfol As Variant)
Dim fso As New FileSystemObject
Dim fld As Folder
Dim tFld As Folder
'Dim sfol As String

Application.ScreenUpdating = False
'sfol = "N:\Database"
Set fld = fso.GetFolder(sfol)
i = 0
For Each tFld In fld.SubFolders
i = i + 1

Cells(i, 1).Value = tFld.Name
Cells(i, 2).Value = tFld.Size
Cells(i, 3).Value = Cells(i, 2) / 1024
Cells(i, 4).Value = tFld.DateCreated
Cells(i, 5).Value = tFld.DateLastModified
With Application.FileSearch
.NewSearch
.LookIn = tFld
.SearchSubFolders = False
.Filename = "Project.inf"

If .Execute() 0 Then
ReDim Preserve Myfiles(1 To .FoundFiles.Count)
Application.StatusBar = "Found Files: " & .FoundFiles.Count
For i = 1 To .FoundFiles.Count
Myfiles(i) = .FoundFiles(i)
Next i
Else
MsgBox "There were no files found"
Exit Sub
End If
End With

If tFld.Size < 200 Then
tFld.Delete True
Cells(i, 6).Value = "Deleted"
End If
Next

Application.ScreenUpdating = True
End Sub




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 you save an excel file to be read as IBM-type text file ? Dee Franklin Excel Worksheet Functions 2 October 10th 06 02:46 AM
read text file hallie Excel Programming 2 August 17th 04 01:00 PM
read text file hallie Excel Programming 1 August 17th 04 12:37 PM
Read data from a text file (*.txt) Adrian T Excel Programming 0 June 4th 04 10:00 PM
Read text file jacob[_3_] Excel Programming 2 September 23rd 03 06:41 PM


All times are GMT +1. The time now is 03:21 PM.

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"