VB Script to open multiple folders on HD & provide file property details.

Laura Boyd

New Member
Joined
Sep 10, 2017
Messages
2
Hello all...


I am creating a database spreadsheet for files I have on my hard drive. I found the script I want, and it works, but there are 2 functions I would like to have it do to smooth the process.


What this code does is pulls all the files in 1 folder & gives me the data from the "Properties/Details" tab of the file. I found the information I want it to provide & its working like a charm. However the issue is, I need it to open the folders within the folder I selected.


Example:
Files I want are in: G:/#
G:/A
G:/B
G:/C
G:/D
and so on until G:/Z


If I select G:/ it just provides the folder names and not any files within those folders. If I select G:/# I get the files I wanted in that folder, but it won't pull from the other folders. So ultimately, I THINK (I am a self teacher of excel & am FAR from a pro, so you all please help if there is an easier process) what I need to do is add a code that will automatically selected the G drive when I run the macro (right now it has a popup window asking for the folder location) and then the code will repeat over and over to automatically go through each folder running the script until there is no more folders to open.


I hope this made sense, I tried to be as detailed as possible but if someone would like to see my excel sheet I am working with, I won't mind sharing.


Code is:
Code:
Option Explicit
Sub GetDetails()
  Dim oShell As Object
  Dim oFile As Object
  Dim oFldr As Object
  Dim lRow As Long
  Dim iCol As Integer
  Dim vArray As Variant
  vArray = Array(1, 4, 9, 13, 15, 16, 18, 21, 24, 27)  
  Set oShell = CreateObject("Shell.Application")
  lRow = 1
  With Application.FileDialog(msoFileDialogFolderPicker)
    .Title = "Select the Folder..."
    If .Show Then
      Set oFldr = oShell.Namespace(.SelectedItems(1))
      With oFldr
        For iCol = LBound(vArray) To UBound(vArray)
          Cells(lRow, iCol + 1) = .getdetailsof(.items, vArray(iCol))
        Next iCol
        For Each oFile In .items
          lRow = lRow + 1
          For iCol = LBound(vArray) To UBound(vArray)
            Cells(lRow, iCol + 1) = .getdetailsof(oFile, vArray(iCol))
          Next iCol
        Next oFile
      End With
    End If
  End With
End Sub


Thanks for any help provided in advance :)
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,215,537
Messages
6,125,398
Members
449,222
Latest member
taner zz

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