Mark harris
Mark harris

Reputation: 543

show a message box containing a list of all files in a directory except one?

I am trying to bring up a message box in excel showing a list of all the files in a directory like so:

 Dim StrFile As String
    StrFile = Dir("S:\Tasks\Tenders\" & Range("M" & ActiveCell.Row).Value & "\" & Range("Z" & ActiveCell.Row).Value & "\*.*")
    StrFile = Dir
        MsgBox StrFile

the problem have at the moment is this only shows one file out of a possible 20.

I am trying to get all the files in the folder listed in the message box like so:

File 1
File 2
File 3
etc

I also have a file called log.txt which I want to exclude from being listed.

Please can someone show me the best way to do this? Thanks in advance

Upvotes: 1

Views: 1401

Answers (1)

RBarryYoung
RBarryYoung

Reputation: 56725

IIRC, you should do it like this:

Dim StrFile As String, StrFiles as String
StrFile = Dir("S:\Tasks\Tenders\" & Range("M" & ActiveCell.Row).Value & "\" & Range("Z" & ActiveCell.Row).Value & "\*.*")

Do While StrFile <> ""
    If StrFile <> "log.txt" Then StrFiles = StrFiles & vbCrLf & StrFile
    StrFile = Dir
Loop

MsgBox StrFiles

Upvotes: 1

Related Questions