我如何将此Excel VBA修改为:
这是当前的VBA:
Sub MM()
Dim fResults As Variant
fResults = GetFiles("C:\Temp")
Range("A1").Resize(UBound(fResults) + 1, 1).Value = _
WorksheetFunction.Transpose(fResults)
End Sub
// UDF to populate array with files, assign to a Variant variable.
Function GetFiles(parentFolder As String) As Variant
GetFiles = Filter(Split(CreateObject("WScript.Shell").Exec("CMD /C DIR """ & parentFolder & _
IIf(Right(parentFolder, 1) = "\", vbNullString, "\") & "*.*"" /S /B /A:-D").StdOut.ReadAll, vbCrLf), ".")
End Function
答案 0 :(得分:2)
答案是更改dir命令的参数。
使用:
DIR /S /B /A-H-S
当前指定的-D隐藏目录。 有关dir参数的完整说明,请参见https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/dir
答案 1 :(得分:2)
您的Filter…IIF…结构也将删除目录。摆脱它。
GetFiles = Split(CreateObject("WScript.Shell").Exec("cmd /c dir """ & parentFolder & """ /A-H-S /B /S").StdOut.ReadAll, vbNewLine)
可能会更好地做您想做的事