Этот код powershell работает в консоли:
Get-ChildItem -Path "P:\ADL Electrical\Australian Standards\Electrical Specific Australian Standards\" *.* -Recurse | Select-Object Directory, Name, CreationTime, LastwriteTime | sort-object -property Name | Export-csv "c:\temp\test2.csv"
Этот код VBA теперь работает.
Sub Process_Click()
Dim retVal
Dim sSource As String
Dim sTarget As String
sSource = "P:\ADL Electrical\Australian Standards\Electrical Specific Australian Standards\"
sTarget = "c:\temp\test2.csv"
retVal = Shell("POWERSHELL.exe -nologo -windowstyle hidden -noexit Get-ChildItem -Path " & sSource & " *.* -Recurse | Select-Object Directory, Name, CreationTime, LastwriteTime | sort-object -property Name | Export-csv " & sTarget & "", 1)
MsgBox (Range("E10").Value)
Debug.Print pscmd
End Sub
Теперь отлично работает с помощью Siddharth.