+ Reply to Thread
Results 1 to 2 of 2

VBA FileSystemObject Properties: Dimensions, Size and Vertical resolution

Hybrid View

  1. #1
    Registered User
    Join Date
    11-13-2013
    Location
    Newpoert News, Virginia
    MS-Off Ver
    Excel 2007
    Posts
    1

    VBA FileSystemObject Properties: Dimensions, Size and Vertical resolution

    I have a VBA script that lists the file names and some of the file properties contained in a folder. I'd like to retrieve file properties of Dimensions and Vertical resolution as well. Are these properties available via FileSystemObject Properties? Or is there another way to pull this metadata? My script is below.

    Cheers!

    Sub TestListFilesInFolder()
    'Workbooks.Add ' create a new workbook for the file list
    ' add headers
    Dim Folder As String, InputFolder As String
    MsgBox ("Please locate and select the folder containing the vendor's files.")
    Folder = Application.GetOpenFilename("Folder, *")
    InputFolder = getFilePath(Folder)
    With Range("A1")
    .Formula = "Folder contents:"
    .Font.Bold = True
    .Font.Size = 12
    End With
    Range("A3").Formula = "File Name:"
    Range("B3").Formula = "File Size:"
    Range("C3").Formula = "File Type:"
    Range("D3").Formula = "Date Created:"
    Range("E3").Formula = "Date Last Accessed:"
    Range("F3").Formula = "Date Last Modified:"
    Range("G3").Formula = "Attributes:"
    Range("H3").Formula = "Short File Name:"
    Range("A3:H3").Font.Bold = True
    ListFilesInFolder InputFolder, True
    ' list all files included subfolders
    End Sub

    Sub ListFilesInFolder(SourceFolderName As String, IncludeSubfolders As Boolean)
    ' lists information about the files in SourceFolder
    ' example: ListFilesInFolder "C:\FolderName\", True
    Dim FSO As Scripting.FileSystemObject
    Dim SourceFolder As Scripting.Folder, SubFolder As Scripting.Folder
    Dim FileItem As Scripting.File
    Dim r As Long
    Set FSO = New Scripting.FileSystemObject
    Set SourceFolder = FSO.GetFolder(SourceFolderName)
    r = Range("A65536").End(xlUp).Row + 1
    For Each FileItem In SourceFolder.Files
    ' display file properties
    Cells(r, 1).Formula = FileItem.Name
    Cells(r, 2).Formula = FileItem.Size
    Cells(r, 3).Formula = FileItem.Type
    Cells(r, 4).Formula = FileItem.DateCreated
    Cells(r, 5).Formula = FileItem.DateLastAccessed
    Cells(r, 6).Formula = FileItem.DateLastModified
    Cells(r, 7).Formula = FileItem.Attributes
    Cells(r, 8).Formula = FileItem.ShortPath
    ' use file methods (not proper in this example)
    ' FileItem.Copy "C:\FolderName\Filename.txt", True
    ' FileItem.Move "C:\FolderName\Filename.txt"
    ' FileItem.Delete True
    r = r + 1 ' next row number
    Next FileItem
    If IncludeSubfolders Then
    For Each SubFolder In SourceFolder.SubFolders
    ListFilesInFolder SubFolder.path, True
    Next SubFolder
    End If
    Columns("A:H").AutoFit
    Set FileItem = Nothing
    Set SourceFolder = Nothing
    Set FSO = Nothing
    ActiveWorkbook.Saved = True
    End Sub
    Function getFilePath(path As String)

    Dim filePath() As String
    Dim finalString As String
    Dim x As Integer
    filePath = Split(path, "\")

    For x = 0 To UBound(filePath) - 1
    finalString = finalString & filePath(x) & "\"
    Next

    getFilePath = finalString
    End Function

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA FileSystemObject Properties: Dimensions, Size and Vertical resolution

    Please take a moment to read the forum rules, use code tags and post links to cross-posts on other forums.

    Also, are you talking about images here? you want to know the size and resolution of a bunch of images? Maybe have a look here:
    http://www.excelforum.com/excel-prog...excel-vba.html

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Calculate dimensions of needed box based on size of machine being packed???
    By Denny Morgan in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-28-2012, 05:36 AM
  2. Array Size & Dimensions Best Practice
    By pipsturbo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-26-2011, 11:34 AM
  3. Changing screen resolution - combo box size grows larger/smaller
    By Carlsbergen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-21-2010, 06:50 AM
  4. Option Button on sheet changes size in 1024 by 768 resolution
    By Michael Tress in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-13-2006, 05:10 PM
  5. screen resolution => vertical graph title problems
    By bartelj in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 12-20-2005, 05:10 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1