显示包含目录中除一个文件之外的所有文件的列表的消息框?

时间:2022-01-26 15:21:35

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

我试图在excel中打开一个消息框,显示一个目录中所有文件的列表,如下所示:

 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.

目前的问题是,这只显示了一个可能的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.

我还有一个名为log的文件。我想把它排除在列表之外。

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

谁能告诉我做这件事最好的方法吗?谢谢提前

1 个解决方案

#1


1  

IIRC, you should do it like this:

IIRC,你应该这样做:

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

#1


1  

IIRC, you should do it like this:

IIRC,你应该这样做:

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

相关文章