View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default macro adjustment

Hi,

To make it work for any sheet with a director in a1 try this. Alt+F11 to
open VB editor. Double click 'This workbook' and paste this in. Enter a valid
dirextory into A1 for the listing

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If ActiveSheet.Range("A1").Value = "" Then Exit Sub
Application.EnableEvents = False
Folder = Range("A1").Value
On Error GoTo 200
Set fso = CreateObject _
("Scripting.FileSystemObject")

Set Folder = fso.GetFolder(Folder)

RowNumber = 2
'folder size in bytes
On Error GoTo 200
For Each fl In Folder.Files
ActiveSheet.Cells(RowNumber, "C") = fl.DateLastModified
ActiveSheet.Cells(RowNumber, "B") = fl.Size
ActiveSheet.Cells(RowNumber, "A") = strFolder & fl.Name
RowNumber = RowNumber + 1
Next fl

200 On Error GoTo 0
Application.EnableEvents = True
End Sub


Mike

"driller" wrote:

Dear All,

i have this basic macro provide by forum member that can do a lot of work.
but due to more demands, i like that this macro can be separately operated
made for each sheets in one workbook.
In a way that when i place in A1 the text for Target Directory, the macro
will react and give result on the opened sheet starting from Row 2.
Same will go for other sheets in one workbook. I have 50 Folders that
contains a 100 different files, and these files are oftenly increased,
replaced or deleted.
Thats why I need this Macro very badly to produce a working comparative
workbook in a weekly bloody basis.

here below is the nice macro

Sub getdates()
Folder = "D:\My Documents\FOLDER-1"
Set fso = CreateObject _
("Scripting.FileSystemObject")

Set Folder = _
fso.GetFolder(Folder)

RowNumber = 1
'folder size in bytes
On Error GoTo 200
For Each fl In Folder.Files
Sheets(1).Cells(RowNumber, "C") = fl.DateLastModified
Sheets(1).Cells(RowNumber, "B") = fl.Size
Sheets(1).Cells(RowNumber, "A") = strFolder & fl.Name
RowNumber = RowNumber + 1
Next fl

200 On Error GoTo 0

Im not good in reading between the lines of this language...please help.
Thanks in advance.

--
best regards,