macro for file size

mikieprojects48

New Member
Joined
Jun 5, 2011
Messages
9
I have a macro that will show me the file size of a file. It should be simple I know, I have lloked over the internet and not getting anywhere. here is a the code that I got from a book.I'm getting a run time error 53 and the debug says theres a problem with the last line. Any help would be appreciated.

Sub GetFileSize()
Dim TheFile As String
TheFile = "G:\DWG"
MsgBox FileLen("TheFile")
End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
New at VBA you are pointing me in the right direction. this is the code now.But the only thing that shows up in the message box is FileSize. I need to figure out what I'm missing to bring up the actual file size in bytes, also again thanks
Sub GetFileSize()
Dim FileSize As String
FileSize = "G:\"
MsgBox "FileSize"

End Sub.
 
Upvote 0
Here's what Andrew meant:
Code:
Sub GetFileSize()
    Dim TheFile As String
    TheFile = "G:\DWG"
    MsgBox FileLen(TheFile)
End Sub

An alternative would be to skip the use of the variable:

Code:
Sub GetFileSize()
    MsgBox FileLen("G:\DWG")
End Sub
 
Last edited:
Upvote 0
I'm getting whatever I tell it to in the msgbox. I wonder if there is some kind of safety block on my hard-drives or PC, thank for the help
 
Upvote 0
Amen LOL! I was trying to get the size of my external thumb drive, that was one of the problems. When I gave it a particular file to look at this code worked.

Sub Get_File_Size()
Dim FILE1 As String
FILE1 = "F:\Cell phone pictures 01-01-09\DUKE.jpg"
MsgBox "The Size of the File is " & FileLen(FILE1) & " bytes"

End Sub

Thanks for the input, have a good day.
mp
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,543
Members
452,924
Latest member
JackiG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top