This gives you names and sizes for all .xls files in the directory
containing the open workbook:
Sub dir_test()
Dim fs, f, s
Dim filespec As String
Dim count As Integer
count = 1
Set fs = CreateObject("Scripting.FileSystemObject")
filespec = Dir(ActiveWorkbook.Path & "\*.xls")
Do While filespec <> ""
Set f = fs.GetFile(filespec)
s = f.Size
n = f.Name
Range("A" & count) = n
Range("B" & count) = s & " KB"
filespec = Dir
count = count + 1
Loop
End Sub
For one specific file:
Sub dir_test()
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile("H:\excel\Dir1.xls")
Range("A1") = f.Name
Range("B1") = f.Size & " KB"
End Sub
Claud Balls - 18 Feb 2005 01:32 GMT
I should have added, double click ThisWorkbook in the VB Editor and use:
Private Sub Workbook_Open()
to run code when a workbook is opened.
guete227 - 13 Dec 2006 13:25 GMT
Would the code below pertain to only the workbook open?
Thanks.
>I should have added, double click ThisWorkbook in the VB Editor and use:
>Private Sub Workbook_Open()
>
>to run code when a workbook is opened.