Thread
:
How to write a macro to print a dir on my c drive
View Single Post
#
2
Posted to microsoft.public.excel.programming
Don Guillett[_4_]
external usenet poster
Posts: 2,337
How to write a macro to print a dir on my c drive
Here are a couple you might try
Sub GetFileList()
Dim iCtr As Integer
With Application.FileSearch
.NewSearch
.LookIn = "c:\aa"
.SearchSubFolders = True
.Filename = ".xls"
If .Execute 0 Then
For iCtr = 1 To .FoundFiles.Count
Cells(iCtr, 1).Value = .FoundFiles(iCtr)
Next iCtr
End If
End With
End Sub
Sub FindExcelFiles()
Application.ScreenUpdating = False
Dim FN As String ' For File Name
Dim ThisRow As Long
Dim FileLocation As String
FileLocation = "c:\ahorse\*.xls"
FN = Dir(FileLocation)
Do Until FN = ""
ThisRow = ThisRow + 1
Cells(ThisRow, 1) = FN
FN = Dir
Loop
Application.ScreenUpdating = True
End Sub
--
Don Guillett
SalesAid Software
"Tony" wrote in message
...
I have tried to right a macro to get the file nanes of the files in a dir
on
my c; drive but only get \*.* as a results. And debug takes me to the
Print_file = dir() I can not get it to work. Can anyone tell me whats
incorrect in the file below.
Sub Print_Dir_Contents()
Dim Input_Dir, Print_File As String
Input_Dir = InputBox("Input the path containing the files you " & _
"want to list on your worksheet" & Chr(13) & Chr(13) & _
"for example:C:\My Documents\*.*")
If Input_Dir = "" Then Exit Sub
' If you want only to print a specific file type, you can
' substitute the "\*.*" with "*\.xl*"
' (for Excel files only) for the directory specified in the
' InputBox above.
If Application.OperatingSystem Like "*Win*" Then
Print_File = Dir(Input_Dir) & "\*.*"
End If
Range("a1").Select
Counter = 1
Do While Len(Print_File) 0
Worksheets(ActiveSheet.Name).Cells(Counter, 1).Value = _
Print_File
Print_File = Dir()
Counter = Counter + 1
Loop
Thanks if you can help
Tony
Reply With Quote
Don Guillett[_4_]
View Public Profile
Find all posts by Don Guillett[_4_]