Home Excel Powerpoint Word Outlook Error Codes

VBA Useful Codes

Welcome to the World of VBA
Home > VBAUsefulCodes

Get all File Names in a Directory

Get all file names inside the folder or directory using Fileystemobject in vba macros.

Sub GetAllFilesinDirectory()

Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim ws As Worksheet

Set objFSO = CreateObject("Scripting.FileSystemObject")

folderpath = "C:\"
Set objFolder = objFSO.GetFolder(folderpath)

'Loop through the Files collection
For Each objFile In objFolder.Files
MsgBox objFile.Name

'Clean up!
Set objFolder = Nothing
Set objFile = Nothing
Set objFSO = Nothing

End Sub


Enter your e-mail below and get notified on the latest blog posts.


VBA Outlook KPI Excel Alt+F11 Dashboards Macros Recording Graphs Automation Developer WaterFall Powerpoint Charts Pivot Tables Forecast Charts

Follow Us