Calling a Powershell Script from VBA in Access RRS feed

  • Question

  • I want to call a PowerShell script from VBA in Access 2010. Here's the code I'm using in VBA:

    runSendreports = Shell("Powershell.exe C:\Windows\System32\WindowsPowerShell\v1.0\MyScript.ps1", vbNormalFocus)

    The PowerShell window opens very briefly with this error message:

    MyScript.ps1 : The term 'MyScript.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

    If I copy and paste everything between the double quotes in my code into the Windows search box or into a Command Prompt window, it runs perfectly. Any ideas what I'm missing?

    Thursday, February 7, 2013 10:02 PM


  • Apparently VBA can't run a script from within the v1.0 folder. I created a folder called Tasks under c:\program files\ and gave my account Modify permissions to it, then moved my script there. I changed the code to this:

    runSendreports = Shell("Powershell.exe -executionpolicy bypass C:\Progra~1\Tasks\MyScript.ps1")

    And now it works.

    • Marked as answer by reprac Thursday, February 7, 2013 11:04 PM
    Thursday, February 7, 2013 11:03 PM