vba 计算特定文件夹中的文件并将数字显示为 1 cel

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16753701/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 15:40:21  来源:igfitidea点击:

count files in specific folder and display the number into 1 cel

filevbaxls

提问by user2151190

I am trying to know how many files there are in 1 specific folder with .xls extension. I read hundreds of examples with message boxes, but that is not what I'm looking for. I just want to have the number displayed into 1 cel.

我想知道 1 个扩展名为 .xls 的特定文件夹中有多少文件。我阅读了数百个带有消息框的示例,但这不是我想要的。我只想将数字显示为 1 cel。

Is there someone who likes to help me with that please? I can not post any attempts because I can not get started :-(

有没有人愿意帮我解决这个问题?我无法发布任何尝试,因为我无法开始:-(

best regards, E.

最好的问候,E。

回答by Santosh

Try below code :

试试下面的代码:

Assign the path of the folder to variable FolderPathbefore running the below code.

FolderPath在运行以下代码之前将文件夹的路径分配给变量。

Sub sample()

    Dim FolderPath As String, path As String, count As Integer
    FolderPath = "C:\Documents and Settings\Santosh\Desktop"

    path = FolderPath & "\*.xls"

    Filename = Dir(path)

    Do While Filename <> ""
       count = count + 1
        Filename = Dir()
    Loop

    Range("Q8").Value = count
    'MsgBox count & " : files found in folder"
End Sub