Home > front end >  Why isn't execution of system command working in VBA macro?
Why isn't execution of system command working in VBA macro?

Time:09-17

I have a working command that unzips zip file when passed to command line. However, when I try to execute this command from VBA macro, it isn't doing anything. VBA:

Sub Test()
Shell("powershell.exe -command Expand-Archive -Force C:\Test\test.zip C:\Test\")
End Sub

I've also tried:

Sub Test()
Call Shell("powershell.exe -command Expand-Archive -Force C:\Test\test.zip C:\Test\", vbNormalFocus)
End Sub

Thank you for your suggestions ;)

CodePudding user response:

I made it work:

Sub Test()
Set objShell = CreateObject("Wscript.Shell")
objShell.Run("powershell.exe -command Expand-Archive -Force C:\Test\test.zip C:\Test\")
End Sub()

CodePudding user response:

Please, try it in this way:

Sub TestUnzip()
    Shell "powershell.exe Expand-Archive -Force C:\Test\test.zip C:\Test\" 
End Sub

Of course, a "test.zip" file must exist in "C:\Test" folder...

If the full name will contain spaces, it must be placed between quotes:

'C:\My Test\test.zip'
'C:\Test\first test.zip'
  • Related