Ask a question »

Import file names in Excel

April 2015


Issue

I have a folder with a series of Outlook files (with the .msg extension), and I want to import all file names in an Excel file (2007). Is there any macro for this purpose?

Solution

Adapt this code accordingly:
Sub repertorier_fichier()
Dim Chemin As String, Fichier As String

'indique le répertoire contenant les fichiers
Chemin = "C:\MONDOSSIER\"

'Boucle sur tous les fichiers msg du répertoire.
Fichier = Dir(Chemin & "*.msg")

numligne = 1

Do While Len(Fichier) > 0
Sheets("Feuil1").Range("A" & numligne).Value = Fichier
numligne = numligne + 1
Fichier = Dir()
Loop
End Sub

Thanks to rv83toulon for this tip.
For unlimited offline reading, you can download this article for free in PDF format:
Import-file-names-in-excel.pdf

See also

In the same category

Published by aakai1056. - Latest update by Jeff
This document entitled « Import file names in Excel » from Kioskea (en.kioskea.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.