File Size

K

Kerry

Hi

I am using Word XP

I have a procedure which saves the current file and shows
me the file size (to check against e-mail attachment size
policy). The problem is that the size is only shown in K,
I would really like it to be MB or a decimal of MB. I
have tried calculating but seems to give rather strange
answers.

Can this be done?? I have searched newsgroups, support
sites and books but cannot find a thing about file size in
MB.

Thanks very much.

Kerry.
--------------------------
Original Code:-

Dim CurrName As String
Dim lflen As Long

ActiveDocument.Save
CurrName = ActiveDocument.FullName
lflen = FileLen(CurrName)
fn = MsgBox(lflen & " k",vbOKOnly,"Current File Size")

Calculation Test Code:

Dim CurrName As String
Dim lflen As Single

ActiveDocument.Save
CurrName = ActiveDocument.FullName
lflen = FileLen(CurrName)
lflen = lflen / 1024
fn = MsgBox(lflen & " mb", vbOKOnly, "Current File
size")
 
S

Steve Franks

The first problem is the statement Dim lflen As Long
Long variables only hold integers.
The second is that FileLen(CurrName) returns a value in bytes, so this needs
to be divided by 1024, then further divided by 1024 to convert it to
megabytes.

I would suggest that you repolace the divisons by lflen = Round(lflen /
1024, 4)
to present the result with a fixed number of decimal places.
I hope that this helps,
Regards
Steve
 
K

Kerry

Great - Thanks v much Steve

Please see the code below for anyone looking at this
question.

Sub CheckSize()
'Save document & show current file size in mb
Dim CurrName As String
Dim lflen As Single

ActiveDocument.Save
CurrName = ActiveDocument.FullName
lflen = FileLen(CurrName)
lflen = lflen / 1024
lflen = Round(lflen / 1024, 2)
fn = MsgBox(lflen & " mb", vbOKOnly, "Current File Size")
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top