+ Reply to Thread
Results 1 to 14 of 14

Help with displaying file size

  1. #1
    Forum Contributor
    Join Date
    01-04-2013
    Location
    Arkansas
    MS-Off Ver
    Microsoft Excel 2016
    Posts
    252

    Help with displaying file size

    I shamelessly found this VBA to search and display video path, file name, duration and size. How do I make it display the size of the file as either kb, mb or gb?

    Please Login or Register  to view this content.
    If I knew who the original author of this code was, I would give him credit.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Help with displaying file size

    No "shame" in using code posted on the web for you, that's why it's there.

    The existing macro is dividing filesize by 1024 (look for those instances in the code), so you will simply change that to whatever you want the display shown as.

    1024 probably gives you Kb.

    1024*1024 would give megabytes (1048576)

    etc....
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor
    Join Date
    01-04-2013
    Location
    Arkansas
    MS-Off Ver
    Microsoft Excel 2016
    Posts
    252

    Re: Help with displaying file size

    Quote Originally Posted by JBeaucaire View Post
    No "shame" in using code posted on the web for you, that's why it's there.

    The existing macro is dividing filesize by 1024 (look for those instances in the code), so you will simply change that to whatever you want the display shown as.

    1024 probably gives you Kb.

    1024*1024 would give megabytes (1048576)

    etc....
    Thanks for the help. This is what it brings up for the file size:

    -1122MB

    Why the (-)?

  4. #4
    Forum Contributor
    Join Date
    01-04-2013
    Location
    Arkansas
    MS-Off Ver
    Microsoft Excel 2016
    Posts
    252

    Re: Help with displaying file size

    I have attached the file that I'm working on. If I could get the correct size of the file (KB,MB,GB) in column D, that would be excellent.
    Attached Files Attached Files

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Help with displaying file size

    I'm unable to run that macro on my 64bit system so must trust that it works for you.

    As noted previously, you must edit the 1024 references (1024=kb) to the number you prefer instead.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    01-04-2013
    Location
    Arkansas
    MS-Off Ver
    Microsoft Excel 2016
    Posts
    252

    Re: Help with displaying file size

    Quote Originally Posted by JBeaucaire View Post
    I'm unable to run that macro on my 64bit system so must trust that it works for you.

    As noted previously, you must edit the 1024 references (1024=kb) to the number you prefer instead.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Thanks again for the reply.

    My system is 64bit, don't understand why it wouldn't work for you as well.

    This is what I get when I use
    Please Login or Register  to view this content.
    -2049596673024 gb

    Don't know why the negative and the file is actually 2.13gb, according to the properties.

  7. #7
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Help with displaying file size

    You did not follow Jerry's instructions. Parentheses are important. Try:
    Please Login or Register  to view this content.
    Lewis

  8. #8
    Forum Contributor
    Join Date
    01-04-2013
    Location
    Arkansas
    MS-Off Ver
    Microsoft Excel 2016
    Posts
    252

    Re: Help with displaying file size

    Quote Originally Posted by LJMetzger View Post
    You did not follow Jerry's instructions. Parentheses are important. Try:
    Please Login or Register  to view this content.
    Lewis
    I get a run-time error of '6': Overflow when I tried that.

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Help with displaying file size

    So maybe it's:
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 02-20-2017 at 10:26 PM.

  10. #10
    Forum Contributor
    Join Date
    01-04-2013
    Location
    Arkansas
    MS-Off Ver
    Microsoft Excel 2016
    Posts
    252

    Re: Help with displaying file size

    Quote Originally Posted by JBeaucaire View Post
    So maybe it's:
    Please Login or Register  to view this content.
    That is so close. It brings up:
    -2gb
    The file is 2.13gb

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Help with displaying file size

    The math is correct. At this point I'd check the formatting in the cell.

  12. #12
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Help with displaying file size

    If you want 2.13 then round to 2 places instead of 0 by replacing .../ 1024 , 0 ) with .../ 1024 , 2 )
    Last edited by kev_; 02-23-2017 at 07:18 PM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  13. #13
    Forum Contributor
    Join Date
    01-04-2013
    Location
    Arkansas
    MS-Off Ver
    Microsoft Excel 2016
    Posts
    252

    Re: Help with displaying file size

    I'm just going to have to try something else. No matter what I try on this line, it just won't bring up the correct file size.

    Thanks for all the help.

  14. #14
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Help with displaying file size

    This is what Kev was talking about:

    Please Login or Register  to view this content.
    Change that 0 to a 2, or however many decimal places you want to allow.

+ 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. Replies: 9
    Last Post: 05-18-2023, 07:18 PM
  2. Size of Size of the Excel File saved on a networkdrive
    By cpmsimoes in forum Excel General
    Replies: 0
    Last Post: 08-12-2015, 06:01 AM
  3. How to get file size from a given folder as input and categorize the files based on size
    By mahendra.asapu in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-27-2015, 05:49 PM
  4. .xlsm file not displaying cells at correct size
    By MilesWilliams in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 10-16-2013, 11:58 PM
  5. Userform is not displaying at the size I've set in the properties
    By Telperion in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-07-2013, 02:35 PM
  6. Replies: 6
    Last Post: 01-20-2013, 09:52 AM
  7. [SOLVED] Displaying the size of the dataset currently in memory
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-16-2006, 09:50 AM

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