• VBA FileSystemObject Properties: Dimensions, Size and Vertical resolution

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » VBA FileSystemObject Properties: Dimensions, Size and Vertical resolution

    Author
    Topic
    #491925

    I have a VBA script that lists the file names contained in a folder. I’d like to retrieve file properties of Dimensions, Size and Vertical resolution along with the file name. Are these properties available via FileSystemObject Properties? Or is there another way to pull this metadata?

    Cheers!

    Viewing 1 reply thread
    Author
    Replies
    • #1422777

      I don’t think those properties are available via FileSystemObject. The Folder Method GetDetailsOf, seems to have 287 properties (from 0 to 286) which contains those (as well as many others. Here is some Excel VBA code that ask for a folder and then list the Name, dimensions, size and vertical resolution in the activesheet.

      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(0, 31, 1, 163)
        '0=Name, 31=Dimensions, 1=Size, 163=Vertical Resolution
        
        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

      The “Dimensions” is a combination of the Width and Height (it concatenates: Width x Height). If you want the individual values, the width is item 162 and the Height is Item 164. Also, you did not ask, but the horizontal resolution is 161. If you want to see the complete list of the details and their number you can run the following with a blank sheet active. Note that many files have none of the details listed and some are file specific. For example the MP3 details can be obtained this way as well.

      Code:
      Option Explicit
      Sub ListAllDetails()
        Dim oShell As Object
        Dim x As Integer
        Set oShell = CreateObject("Shell.Application")
        With oShell.Namespace("C:")
          For x = 0 To 286
            Cells(x + 1, 1) = x
            Cells(x + 1, 2) = .getdetailsof(.items, x)
          Next x
        End With
      End Sub

      Steve

    • #1422863

      Thank you, WS Lounge VIP. This works like a charm.
      35485-list-image

    Viewing 1 reply thread
    Reply To: VBA FileSystemObject Properties: Dimensions, Size and Vertical resolution

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: