?
Solved

Excel 2010: Function to acquire file size in bytes

Posted on 2012-03-17
3
Medium Priority
?
272 Views
Last Modified: 2012-03-18
For the purpose of planning play list play times, is there an Excel function to get a file's size in bytes?

For example column A, I list MP3 files by name, for example: (The file in A34)
     E:\Music\PlayList1\The Little River Band - Down On The Border.MP3

Is there an excel function such as "FileSizeOf(A34)"  and return  4022196
     (the actual size of the file in bytes)

TIA - Ed
0
Comment
Question by:Ed Covney
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 42

Accepted Solution

by:
dlmille earned 2000 total points
ID: 37734139
Yes, you can do that.  Attached, I wrote your function which you can use like you asked.  I also create a macro to just give you the result on all files in column A (which may be faster/more efficient).

PS - the FileLen() function will provide size in bytes up to 4GB.

Function fileSizeOf(r As Range) As Variant
    On Error Resume Next
    fileSizeOf = FileLen(r.Value)
    On Error GoTo 0
End Function
Sub getFilesizes()
Dim wkb As Workbook
Dim wks As Worksheet
Dim rng As Range
Dim r As Range

    Set wkb = ThisWorkbook
    Set wks = wkb.ActiveSheet
    
    Set rng = wks.Range("A2", wks.Range("A" & wks.Rows.Count).End(xlUp))
    
    For Each r In rng
        r.Offset(, 1).Value = fileSizeOf(r)
    Next r
    
End Sub

Open in new window


See attached demonstration workbook.  Just put your file names  fully pathed in Column A and copy down the formula, or hit the button to just give you the result.

Dave
fileSizeInfo-r1.xls
0
 
LVL 42

Expert Comment

by:dlmille
ID: 37734144
For files of any size you can use this workbook with a function & complimentary macro that returns the file size in GB's instead.  > 4GB would be a very large MP3, but just for completeness, here's that solution ;)

See attached.

Dave
fileSizeInfo-r2.xls
0
 
LVL 3

Author Closing Comment

by:Ed Covney
ID: 37735229
Dave - EXCELLENT !!

Now I just have to figure out how to import your macro into my spreadsheet.
I have lots to learn, thanks for a great start.

Ed
0

Featured Post

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question