excel vba - Reading all folders in VBA -


i put following code in excel. script found on net..

   sub testlistfolders()         application.screenupdating = false         workbooks.add ' create new workbook folder list         ' add headers         range("a1")             .formula = "folder contents:"             .font.bold = true             .font.size = 12         end         range("a3").formula = "folder path:"         range("b3").formula = "folder name:"         range("c3").formula = "size:"         range("d3").formula = "subfolders:"         range("e3").formula = "files:"         range("f3").formula = "short name:"         range("g3").formula = "short path:"         range("a3:g3").font.bold = true         listfolders "c:\foldername\", true         application.screenupdating = true     end sub  sub listfolders(sourcefoldername string, includesubfolders boolean) ' lists information folders in sourcefolder ' example: listfolders "c:\foldername", true dim fso scripting.filesystemobject dim sourcefolder scripting.folder, subfolder scripting.folder dim r long     set fso = new scripting.filesystemobject     set sourcefolder = fso.getfolder(sourcefoldername)     ' display folder properties     r = range("a65536").end(xlup).row + 1     cells(r, 1).formula = sourcefolder.path     cells(r, 2).formula = sourcefolder.name     cells(r, 3).formula = sourcefolder.size     cells(r, 4).formula = sourcefolder.subfolders.count     cells(r, 5).formula = sourcefolder.files.count     cells(r, 6).formula = sourcefolder.shortname     cells(r, 7).formula = sourcefolder.shortpath     if includesubfolders         each subfolder in sourcefolder.subfolders             listfolders subfolder.path, true         next subfolder         set subfolder = nothing     end if     columns("a:g").autofit     set sourcefolder = nothing     set fso = nothing     activeworkbook.saved = true end sub 

the script fails because missing object.

new scripting.filesystemobject 

how object's library? there script can use instead, doesnt rely on object?

vba has built-in functions access file system (e.g. dir), they're pretty unpleasant use.

to make code above work, add reference (tools->references) microsoft scripting runtime".


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -