xmu*_*mux 14
这里如何在Excel Cell中使用它:
=GetDirOrFileSize("C:\Users\xxx\Playground\","filename.xxx")
Run Code Online (Sandbox Code Playgroud)
如果你有一个德国Windows比:
=GetDirOrFileSize("C:\Users\xxx\Playground\";"filename.xxx")
Run Code Online (Sandbox Code Playgroud)
以下是VBA模块的功能:(只需启用开发人员工具,然后将其复制并粘贴到新模块中)
Function GetDirOrFileSize(strFolder As String, Optional strFile As Variant) As Long
'Call Sequence: GetDirOrFileSize("drive\path"[,"filename.ext"])
Dim lngFSize As Long, lngDSize As Long
Dim oFO As Object
Dim oFD As Object
Dim OFS As Object
lngFSize = 0
Set OFS = CreateObject("Scripting.FileSystemObject")
If strFolder = "" Then strFolder = ActiveWorkbook.path
If Right(strFolder, 1) <> "\" Then strFolder = strFolder & "\"
'Thanks to Jean-Francois Corbett, you can use also OFS.BuildPath(strFolder, strFile)
If OFS.FolderExists(strFolder) Then
If Not IsMissing(strFile) Then
If OFS.FileExists(strFolder & strFile) Then
Set oFO = OFS.Getfile(strFolder & strFile)
GetDirOrFileSize = oFO.Size
End If
Else
Set oFD = OFS.GetFolder(strFolder)
GetDirOrFileSize = oFD.Size
End If
End If
End Function '*** GetDirOrFileSize ***
Run Code Online (Sandbox Code Playgroud)