I want to use the below Command-line in VBA Code, the command is to get all .pdf and .docx files recursively and runs just fine in CMD
dir /s *.pdf *.docx
Now In VBA, have the below, which is printing out ALL files recursively and not the specified extensions
Sub Run()
Debug.Print ShellRun("cmd.exe /c dir c:\ /s *.pdf *.docx")
End Sub
Public Function ShellRun(sCmd As String) As String
Dim oShell As Object
Set oShell = CreateObject("WScript.Shell")
Dim oExec As Object
Dim oOutput As Object
Set oExec = oShell.Exec(sCmd)
ShellRun = oExec.StdOut.ReadAll
End Function