💡 Source code:
Step 1. Open the Viual Basic Editor (ALT+F11)
Step 2. Click Tools
Step 3. Click References
Step 4. Scroll down the list, tick the Microsoft Scripting Runtime (scrrun.dll) checkbox and click OK
After that, the following code should be written:
Public Function UDF_LOCALDISK_TOTALSPACE(disk_name As String, _
unit_of_memory_measurement As String) As String
Application.Volatile (-1)
Dim fso As New FileSystemObject
Select Case unit_of_memory_measurement
Case "Byte"
UDF_LOCALDISK_TOTALSPACE = disk_name & " = " & fso.Drives(disk_name).TotalSize & " Byte"
Case "Kb"
UDF_LOCALDISK_TOTALSPACE = disk_name & " = " & Int(fso.Drives(disk_name).TotalSize / (2 ^ 10)) & " Kb"
Case "Mb"
UDF_LOCALDISK_TOTALSPACE = disk_name & " = " & Int(fso.Drives(disk_name).TotalSize / (2 ^ 20)) & " Mb"
Case "Gb"
UDF_LOCALDISK_TOTALSPACE = disk_name & " = " & Int(fso.Drives(disk_name).TotalSize / (2 ^ 30)) & " Gb"
End Select
End Function
#excelvbatutorial
#msexcel
#vba
#excelvba
#microsoftexcel
#tutorial
#exceltutorial
#excelvbatutorial
#udf
#vbaudf
#excelvbaudf
#userdefinedfunction
#userdefinedfunctions
#udflocaldisktotalspace
#localdisktotalspacefunction
#function
#vbatutorial
#localdisktotalspace
#local