vba code for updated file in folder shows in the list

klpw2

New Member
Joined
Dec 22, 2015
Messages
4
Hi guys,

I've come up with the code that list out the folder name, file name with its details in the folder. Currently, I was wondering how could I get the newly added file in folder shows in the list by itself whenever user adds the file in that folder. I don't want to run the vba code everytime when the workbook is opens because there are more than 30k folders. Any help would be much appreciated. Please see below for the code and thanks in advanced.

Code:
Option Explicit
Private Sub Auto_Open()
Dim Cell As Range
Dim objFSO As Object
Dim objFolder As Object
Dim objSubFolder As Object
'Dim i As Integer
Dim fil As Object
Dim sf As Object
Dim col As Integer
Dim rw As Integer
'Dim Number As Integer
Rows("2:" & Range("B" & Rows.Count).End(xlUp).Row + 1).Clear
Application.StatusBar = ""
'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object
Set objFolder = objFSO.GetFolder("C:\Users\maggie\Desktop\low")
Range("A1") = "Folder Name"
Range("B1") = "File Name"
Range("C1") = "Revision Time"
Range("D1") = "Date Updated"
Range("E1") = "Revision Time"
Range("F1") = "Date Updated"
Range("G1") = "Revision Time"
Range("H1") = "Date Updated"
Range("I1") = "Revision Time"
Range("J1") = "Date Updated"
Range("K1") = "Revision Time"
Range("L1") = "Date Updated"
Range("M1") = "Revision Time"
Range("N1") = "Date Updated"
Range("O1") = "Revision Time"
Range("P1") = "Date Updated"
Range("Q1") = "Revision Time"
Range("R1") = "Date Updated"
Range("S1") = "Revision Time"
Range("T1") = "Date Updated"
Range("U1") = "Revision Time"
Range("V1") = "Date Updated"
'Format(Range("D3"), "d-m-yyyy").
rw = 1
'loops through each folder in the directory and prints their names and path
'On Error GoTo handleCancel
'Application.EnableCancelKey = xlErrorHandler
'MsgBox "This may take a long time: press ESC to cancel"
For Each objSubFolder In objFolder.subfolders
Application.StatusBar = objSubFolder.Path & " " & objSubFolder.Name
    'print folder name
    Cells(rw + 1, 1) = objFolder.Name
    'print file name
    Cells(rw + 1, 2) = Left(objSubFolder.Name, 8)
    'col = 4
    'Cells(rw + 1, col).Value = objSubFolder.DateLastModified
    'col = col + 2
    col = 3
            For Each fil In objSubFolder.Files
                If fil.Name <> "Thumbs.db" Then
                If Mid(fil.Name, 9, 1) = "R" And Mid(fil.Name, 10, 1) <= 100 Then
                    Cells(rw + 1, col) = Mid(fil.Name, 10, InStrRev(fil.Name, ".") - 10)
                    Cells(rw + 1, col + 1) = fil.DateLastModified
                    Else
                    Cells(rw + 1, col) = "error"
                    Cells(rw + 1, col + 1) = fil.DateLastModified
               End If
                col = col + 2
                End If
            Next fil
            rw = rw + 1
            Next objSubFolder
handleCancel:
If Err = 18 Then
 MsgBox "You cancelled"
End If
End Sub

Sub Test_Folder_Exist_With_Dir()
If ActiveCell.Column = 2 And ActiveCell.Row > 1 Then


Dim FSO
Dim sFolder As String
Dim sPath As String

sFolder = "C:\Users\maggie\Desktop\low" ' You can Specify Any Folder To Check It
sPath = sFolder & "\" & ActiveCell.Value
Set FSO = CreateObject("Scripting.FileSystemObject")

If FSO.FolderExists(sFolder) Then
Call Shell("explorer.exe " & sPath, vbNormalFocus)
Else
MsgBox "Specified Folder Not Found", vbInformation, "Folder Not Found!"
End If
End If
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,214,611
Messages
6,120,510
Members
448,967
Latest member
screechyboy79

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top