I'm trying to execute a command on command prompt using Shell Script in VBA Excel. When I execute this command on command prompt it works by printing a number as output. But when I call the same command in the script it doesn't show this number in the message box.
Sub Button6_Click()
Dim oShell As Object
Dim objExecObject As Object
Set oShell = CreateObject("WScript.Shell")
Set objExecObject = oShell.Exec("cmd /c convert test2.jpg -fill black +opaque white -fill white -opaque white -print %[fx:w*h*mean]")
MsgBox (objExecObject.StdOut.ReadAll)
End Sub
I think the problem is with the arguments in the Exec function as there are multiple words. So I tried the following by concatenating a string as shown. But this doesn't work either.
Dim command As String
command = "convert test2.jpg -fill black +opaque white -fill white -opaque white -print %[fx:w*h*mean] null:"
Set objExecObject = oShell.Exec("cmd /c " & command)
There seems to be no runtime error and the message box always returns empty without printing the number. To clarify: the convert command is a function provided by ImageMagick.
Please tell me how I can run the convert command in command prompt and print the output of command prompt in the message box.