Não é possível executar o DIR do WScript Shell no VBA?

Eu uso a seguinte função em muitos dos meus projetos VBA. Inicialmente, adicionei a referência ao modelo de objeto de host de scripts do Windows para tirar proveito do Intellisense, mas depois mudei para a ligação tardia para não precisar fazer referência a várias coisas.

Private Function RunCMD(ByVal strCMD As String) As String
    'Runs the provided command
    Dim oShell As Object 'New WshShell
    Dim cmd As Object 'WshExec
    Dim x As Integer
    Const WshRunning = 0

    On Error GoTo wshError

    x = 0
    RunCMD = "Error"
    Set oShell = CreateObject("Wscript.Shell")
    Set cmd = oShell.Exec(strCMD)
    'Debug.Print strCMD
    'Stop
    Do While cmd.Status = WshRunning
        Sleep 100 'for 1/10th of a second
        x = x + 1
        If x > 1200 Then 'We've waited 2 minutes so kill it
            cmd.Terminate
            MsgBox "Error: Timed Out", vbCritical, "Timed Out"
        End If
    Loop

    RunCMD = cmd.StdOut.ReadAll & cmd.StdErr.ReadAll
    Set oShell = Nothing
    Set cmd = Nothing
    Exit Function

wshError:
    On Error Resume Next
    RunCMD = cmd.StdErr.ReadAll
    Resume Next
End Function

Funciona muito bem quando você faz algo comoRunCMD("ping www.bing.com") ouRunCMD("winrs -r:" & strHost & " reg query hklm\system\currentcontrolset\services\cdrom /v start")

ContudoRunCMD("Dir c:\config* /a:-d /b /d /s") falha ecmd.StdErr.ReadAll fornece um erro variável de objeto ou com bloco não definido. Mesmo um simplesRunCMD("Dir") falha.

Por que o DIR faz com que o shell WScript seja um lixo? Mais importante, como posso usar a função DIR do CMD (não a função DIR do VBA!) Para obter uma lista de arquivos que correspondem a um padrão de pesquisa?

questionAnswers(1)

yourAnswerToTheQuestion