Get list of files in C:\Test\ and open

B

Boss

Hi,

I got a code where i can get the list of file which are prsent in C:\ drive...

I need to open them, any ideas...

Thanks!

Private Sub Command3_Click()
Dim dir, folder, files
dir = "C:\Test\"
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(dir)
Set files = folder.files
MyListBox.RowSourceType = "Value List"
For Each file In files
MyListBox.AddItem (file.Name)
Next
End Sub
 
B

BTU_needs_assistance_43

I've got just what you need here. This program will run a search of any file
you specifiy. If you want a more specific search just add onto the .Lookin to
give the exact files you want searched. I like the message boxes but they
arent really neccessary. I have it output the file names in cells in Excel
here but you can modify the code to whatever form you like. Hope this helps.

Private Sub Command1_Click()

With Application.FileSearch
.NewSearch
.LookIn = "C:\"
.SearchSubFolders = True
.LastModified = msoLastModified... (if you want to narrow your search by
recent files only include day, week, month, etc...)
.FileType = msoFileType... (whatever file type you want)
If .Execute > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" Excel file(s) found."
Worksheets("sheet1").Activate
Worksheets("sheet1").Range("A2").Select
For i = 1 To .FoundFiles.Count
ActiveCell.Value = .FoundFiles(i)
ActiveCell.Offset(rowOffset:=1, columnOffset:=0).Activate
Else
MsgBox "There were no Excel files found."
End If
End With

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top