Home > Mobile >  Shell.Execute in VBA is not doing anything
Shell.Execute in VBA is not doing anything

Time:10-14

I am trying to use powershell to extract some files from a zip folder located on a drive where I only have read access to my desktop in a temp folder where I can do whatever I like to them.

Using the code below I get no errors but the powershell code just does nothing. Am I missing something?

Sub unzip_test()
    Dim myshell As Shell32.Shell
    Set myshell = New Shell32.Shell

    Dim args As String
    args = "Expand-Archive -LiteralPath " & "'C:\Users\user1\Desktop\TEMP\examplezip.zip'" & " -destinationpath " & "'C:\Users\user1\Desktop\TEMP\tester'"
    'Debug.Print (args)
    myshell.ShellExecute "powershell", vargs:=args

End Sub

The debug.print prints Expand-Archive -LiteralPath 'C:\Users\user1\Desktop\TEMP\examplezip.zip' -destinationpath 'C:\Users\st11524\Desktop\TEMP\tester'

Also, I have "Microsoft Shell Controls and Automation" checked in my references.

CodePudding user response:

It should work. I think the problem is somewhere in the Expand-Archive call, but you can't see the answer.
The quick fix is to add -NoExit to your call, like this

args = "-NoExit Expand-Archive -LiteralPath " ...

This will allow you to read the error before it closes, but you can't read it from your code. If you need that, have a look here

CodePudding user response:

After testing this on another computer I've come to the conclusion that this is a permissions thing. My personal computer runs the script just fine where my work computer won't. I don't see anything wrong with the code listed above so I will consider this issue resolved.

  • Related