I wish to return file size from VBA to a function call from the old Macro language. I hope to be able to do so for a nominated file and path or for a folder and all its constituents. I’ve made a poor attempt to do so below, and cannot get it right. The other function I use (ZFileJoinPath) is OK. I’d very much appreciate assistance in correcting my ZFileSize.
Regards
Function ZFileSize( _
strFile As String, _
Optional strDir As String) As Boolean
‘Returns size of File in Bytes OR
‘for Folders the size of all files and subfolders in the folder OR
‘FALSE
On Error GoTo ErrHandler
strPathFile = ZFileJoinPath(strFile, strDir)
If strPathFile = “” Then GoTo ErrHandler
ZFileSize = strPathFile.Size
Exit Function
ErrHandler:
ZFileExists = False
End Function
Function ZFileJoinPath( _
File As String, _
Directory As String) As String
’Joins File & Directory into One String
‘File or Directory may be absent
Dim strPath As String
If File = “” Then
ZFileJoinPath = Directory
Exit Function
End If
If Directory = “” Then
ZFileJoinPath = File
Exit Function
End If
strPath = Directory
If Not Right(strPath, 1) = “” Then
strPath = strPath & “”
End If
strPath = strPath & File
ZFileJoinPath = strPath
End Function