Word

Get filesize of document in kilobytes

Ease of Use

Easy

Version tested with

2000, 2002 

Submitted by:

MOS MASTER

Description:

The function will return the filesize of the specified document in kilobytes. 

Discussion:

You have to determine the file size of some documents. This function will help you get that data in kilobytes. 

Code:

instructions for use

			

Option Explicit ' \\ Test sub to return Filesize Sub GetTheSize() Dim sFilePath As String ' \\ Build path to test file in same folder as this document sFilePath = ThisDocument.Path & "\Test Filesize.doc" ' \\ Call function to return filesize MsgBox GetTheFileSize(sFilePath) & " Kb" End Sub ' \\ This Function returns the Filesize in Kb Public Function GetTheFileSize(sPath As String) As Long Dim iChannel As Integer ' \\ Get free channel (file number) iChannel = FreeFile ' \\ Input file by that channel (file number) Open sPath For Input As iChannel ' \\ Return file size GetTheFileSize = Format((LOF(iChannel) / 1024), "#.0") End Function

How to use:

  1. Open your Word document.
  2. Press Alt + F11 to open VBE.
  3. Insert-Module. (Insert -> module)
  4. Paste the code there in the window at right. (F7)
  5. Close VBE (Alt + Q or press the X in the top right hand corner).
  6. Save the file.
 

Test the code:

  1. From Word, press Alt + F8 to open the macro dialog box.
  2. Select GetTheSize
  3. Click Run.
 

Sample File:

Filesize.zip 17.02KB 

Approved by mdmackillop


This entry has been viewed 61 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express