Quantcast
Channel: Call Powershell from VBA
Viewing all articles
Browse latest Browse all 17

Call Powershell from VBA

$
0
0

Hi

I tried your Ed Wilsons script in vbscript:

option explicit

dim objShell

 

Wscript.Echo "Starting"

Set objShell = CreateObject("Wscript.shell")

objShell.run("powershell -executionpolicy bypass -noexit -File D:\IT\PS1\HelloWorld.ps1")

Wscript.Echo "Done"

 

It worked fine.

 

I tried to start Powershell from  Excel vba:

Option Explicit

 

Private Sub CommandButton1_Click()

Dim sCommand As String, sOutput As String

Dim oWshShell As Object, oWshShellExec As Object

 

sCommand = "Powershell -executionpolicy bypass -noexit "

Debug.Print sCommand

Set oWshShell = CreateObject("WScript.Shell")

Set oWshShellExec = oWshShell.Exec(sCommand)

sOutput = oWshShellExec.StdOut.ReadAll

MsgBox (sOutput)

Set oWshShellExec = Nothing

Set oWshShell = Nothing

End Sub

 

But it do not work.

ProcMon shows that Powersheel starts and immediately stops.

“-noexit” has no effect.

 

How do I start Powershell with -noexit from Excel vba?

 

Regards

 

Jan Andersen

Boelsvang 26

DK-2970 Hoersholm

Denmark

 

Mobile:          +45 2022 1196

E-mail:         janand@janand.dk

www:            www.janand.dk

 


Viewing all articles
Browse latest Browse all 17

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>