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
|