Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Nov 2013
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    VBA FileSystemObject Properties: Dimensions, Size and Vertical resolution

    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!

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 341 Times in 334 Posts
    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
    Last edited by sdckapr; 2013-11-14 at 12:02. Reason: Modified code to use folder name details

  4. The Following 2 Users Say Thank You to sdckapr For This Useful Post:

    ferguson (2013-11-14),RetiredGeek (2013-11-14)

  5. #3
    New Lounger
    Join Date
    Nov 2013
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you, WS Lounge VIP. This works like a charm.
    list image.jpg

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •