Hi All;
I am trying to run 2 different codes in PowerShell from VBA. Both lines of code when entered into PowerShell directly work, but from Excel VBA, they don't execute. I've tried both independent of each other just to see if PowerShell was doing anything, but neither code worked and PowerShell didn't do anything. I tried both with PowerShell closed and Opened.
Order of operations:
1) Change the directory to the variable pathway. Pathway is a value stored in a field on a worksheet called Menu. Pathway includes the entire folder string. Something like:
2) Execute PowerShell code. This doesn't include the Change Directory code:
3) Close PowerShell if it opens.
VB Code I tried:
Since this is new ground for me, where am I going wrong and how can I address the roadblock?
Thanks,
Mike
I am trying to run 2 different codes in PowerShell from VBA. Both lines of code when entered into PowerShell directly work, but from Excel VBA, they don't execute. I've tried both independent of each other just to see if PowerShell was doing anything, but neither code worked and PowerShell didn't do anything. I tried both with PowerShell closed and Opened.
Order of operations:
1) Change the directory to the variable pathway. Pathway is a value stored in a field on a worksheet called Menu. Pathway includes the entire folder string. Something like:
Code:
"C:\Users\Desktop\Sandbox\file name correction macro\test files"
2) Execute PowerShell code. This doesn't include the Change Directory code:
Code:
Get-ChildItem -recurse -include *~* | foreach-object { $name = $_.fullname; $newname = $name -replace '~.*\.','.'; rename-item $name $newname }
3) Close PowerShell if it opens.
VB Code I tried:
Code:
Dim StringCommand_tilde As String
Dim Change_Directory As String
'Change_Directory = "CD " & pathway
StringCommand_tilde = "Get-ChildItem -recurse -include *~* | foreach-object { $name = $_.fullname; $newname = $name -replace '~.*\.','.'; rename-item $name $newname } "
Set WshShell = CreateObject("WScript.Shell")
Set WshShellExec = WshShell.Exec(StringCommand_tilde)
strOutput = WshShellExec.StdOut.ReadAll
Since this is new ground for me, where am I going wrong and how can I address the roadblock?
Thanks,
Mike