Sub test()
Dim fso As Object, dri As Object
Dim i As Integer
Range("a1").CurrentRegion.Clear
i = 1
Cells(i, 1).Resize(1, 3) = Array("盘符", "已用空间", "容量")
Set fso = CreateObject("Scripting.FileSystemObject")
For Each dri In fso.Drives
If dri.IsReady Then
i = i + 1
Cells(i, 1) = dri.DriveLetter '盘符
Cells(i, 2) = Format((dri.TotalSize - dri.AvailableSpace) / 1024 ^ 3, "0.0G") '已用空间
Cells(i, 3) = Format(dri.TotalSize / 1024 ^ 3, "0G") '容量
End If
Next
End Sub