Mostrando entradas con la etiqueta get hard drives in Excel VBA. Mostrar todas las entradas
Mostrando entradas con la etiqueta get hard drives in Excel VBA. Mostrar todas las entradas

miércoles, 9 de noviembre de 2016

Excel VBA Code Macro : Recuperar unidades de Disco duro mediante Macros

Para conseguir recuperar las particiones en Excel debe realizar las siguientes acciones:

-Agregar la referencia a Microsoft Scripting.FileSystemObject
-Recuperar y navegar en la colección de los discos y escribir las propiedades en las celdas.


Sub Read_Drives_In_Excel_VBA()

'Excel VBA CODE-MyExcelTools.com

On Error Resume Next

Dim fso
'Declare the variable

'Set the object type Scripting
Set fso = CreateObject("Scripting.FileSystemObject")

'Set the drives collection
Set Drives = fso.Drives

Dim count As Byte

For Each u In Drives
'Recorremos la colección

'Drive
Columns(1).Cells(1).Offset(count, 0).Value = u.DriveLetter

'Free Space
Columns(2).Cells(1).Offset(count, 0).Value = FormatNumber(u.AvailableSpace / 1024 / 1024 / 1024, 2, , , -1)


count = count + 1


Next

'clear the objects
Set Drives = Nothing
Set fso = Nothing
End Sub