Solved

Excel 2010: Function to acquire file size in bytes

Posted on 2012-03-17
3
255 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-SSA
  • 2
3 Comments
 
LVL 41

Accepted Solution

by:
dlmille earned 500 total points
Comment Utility
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 41

Expert Comment

by:dlmille
Comment Utility
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
 

Author Closing Comment

by:Ed-SSA
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article will show you how to use shortcut menus in the Access run-time environment.
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now