vba - List folders in directory, with update function -
im trying list of folders in directory. , have button enables update, on list, without re-creating every time. listing new folder not in excel sheet.
this code have working. able search sheet if folder there, if skip it, if not add it. once update completed filter name in column c
sub folder_names_including_subfolder() application.screenupdating = false dim fldpath dim fso object, j long, folder1 object if activesheet.name = "test" fldpath = "z:\\" elseif activesheet.name = "test1" fldpath = "y:\\" end if cells(3, 1).value = fldpath cells(4, 1).value = "path" cells(4, 2).value = "dir" cells(4, 3).value = "name" cells(4, 4).value = "folder size" cells(4, 5).value = "date created" cells(4, 6).value = "date last modified" cells(4, 7).value = "codec" set fso = createobject("scripting.filesystemobject") set folder1 = fso.getfolder(fldpath) get_sub_folder folder1 set fso = nothing range("a3").font.size = 9 activewindow.displaygridlines = false range("a3:g" & range("a4").end(xldown).row).font.size = 9 range("a4:g4").interior.color = vbcyan application.screenupdating = true end sub sub get_sub_folder(byref prntfld object) dim subfolder object, subfld object, j long each subfolder in prntfld.subfolders j = range("a3").end(xldown).row + 1 cells(j, 1).value = subfolder.path cells(j, 2).value = left(subfolder.path, instrrev(subfolder.path, "\")) cells(j, 3).value = subfolder.name cells(j, 4).value = application.worksheetfunction.rounddown((((subfolder.size / 1024) / 1024) / 1024), 2) & " " & "gb" cells(j, 5).value = subfolder.datecreated cells(j, 6).value = subfolder.datelastmodified cells(j, 7).validation .add type:=xlvalidatelist, alertstyle:=xlvalidalertstop, operator:= _ xlbetween, formula1:="=sheet3!$a$1:$a$5" .ignoreblank = true .incelldropdown = true .inputtitle = "" .errortitle = "" .inputmessage = "" .errormessage = "" .showinput = true .showerror = true end next subfolder each subfld in prntfld.subfolders get_sub_folder subfld next subfld columns("c:f").autofit columns("g").columnwidth = 10 end sub
just test before storing material:
for each subfolder in prntfld.subfolders checkit = subfolder.name if application.worksheetfunction.countif(range("c:c"), checkit) = 0 j = range("a3").end(xldown).row + 1 cells(j, 1).value = subfolder.path cells(j, 2).value = left(subfolder.path, instrrev(subfolder.path, "\")) cells(j, 3).value = subfolder.name cells(j, 4).value = application.worksheetfunction.rounddown((((subfolder.size / 1024) / 1024) / 1024), 2) & " " & "gb" cells(j, 5).value = subfolder.datecreated cells(j, 6).value = subfolder.datelastmodified cells(j, 7).validation .add type:=xlvalidatelist, alertstyle:=xlvalidalertstop, operator:= _ xlbetween, formula1:="=sheet3!$a$1:$a$5" .ignoreblank = true .incelldropdown = true .inputtitle = "" .errortitle = "" .inputmessage = "" .errormessage = "" .showinput = true .showerror = true end end if next subfolder
Comments
Post a Comment