Since a time, I was using this code and it worked before
Sub Call_PowerShell_Script_File_From_Excel_VBA()
'Windows PowerShell ISE >> New Script >> Create 'Hello World.ps1'
' echo "Hello World"
' $x = 1 + 1
' echo $x
'----------------------------------------------------------------
Dim wshShell As Object
Dim wshShellExec As Object
Dim strCommand As String
Dim strOutput As String
strCommand = "Powershell.exe -File ""C:\Users\Future\Desktop\Hello World.ps1"""
Set wshShell = CreateObject("WScript.Shell")
Set wshShellExec = wshShell.Exec(strCommand)
strOutput = wshShellExec.StdOut.ReadAll
MsgBox strOutput
End Sub
I was working on Windows 7 and the code was with no problem. After installing Windows 10, I found the code not working and I got blank message with no output Any ideas ??
** When testing Tim's code I got this message
StdOut:
StdErr: File C:\Users\Future\Desktop\Hello World.ps1 cannot be loaded
because running scripts is disabled on this system. For
more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
+ CategoryInfo : SecurityError: (:) [],
ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnauthorizedAccess