我不是很擅长VBA。我正在尝试创建一个函数来计算以3
开头的文件夹中有多少个子文件夹,例如:
C:\Files\ <This is the main folder>
如果只有一个名为32156
的子文件夹,则会返回1
我发现很多脚本都会对子文件夹进行计数,但还不够熟悉它们。
答案 0 :(得分:2)
试试这个:
Sub TestCalling()
MsgBox fGetFolderCount("C:\Files", "3")
End Sub
Function fGetFolderCount(ByVal FolderPath As String, Optional ByVal Prefix As String = vbNullString) As Long
Dim D As Variant
Dim C As Long
D = Dir(FolderPath & Application.PathSeparator & Prefix & "*", vbDirectory)
While D <> ""
If Left(D, 1) <> "." Then
C = C + 1
End If
D = Dir
Wend
fGetFolderCount = C
End Function