Page 1 of 1

Run directly from VB code

Posted: 2012-06-26T03:18:52-07:00
by Santa911
Win7. Why can I not get it to work when trying to run a certain IM-code directly from some Visual Basic (VBA for Excel). I need to make a work around in which I write a Bat-file which I then run with the Shell command.

If I ex. want to run the following code from VB:

Shell "convert -size 30x24 canvas:#ffcc00 Box0030x0024_FFCC00.gif"

This does not work, but if the same code was in a Bat file and I ran the code:

Shell BatFile

then it works. Can somebody help me with this?

Lars

Re: Run directly from VB code

Posted: 2012-06-26T03:37:40-07:00
by whugemann
You don't need a shell to run a simple IM command; a wsh.run or wsh.exec will do, see http://www.imagemagick.org/Usage/windows/#vb.

Your normally don't have to wrap IM commands by a batch file when running them from VB, so I think that this is a PATH issue. Try to call Convert by its full name, including the path, i.e. %PROGRAMFILE%\ImageMagick-x.x.x\convert

Re: Run directly from VB code

Posted: 2012-06-29T12:00:42-07:00
by Santa911
Whugemann - you are right :D

I couldn't figure it out why my picture was not created. The problem was that the path was write protected and therefore nothing was created. It was difficult to see since the Shell command closes immediatly, so that I could not see any error messages.

Anyway - my problems are solved using: ChDir "C:\Wanted\Subfolder" like in the example below (no bat-file is used, only shell):

Code: Select all

Sub TestIM()
'This works under Excel2010 VBA
Dim CommandIM As String
Dim myFld As String

myFld = "c:\Program Files\ImageMagick-6.7.8-Q16\"
ChDir "C:\Wanted\Subfolder"
CommandIM = "convert -size 30x24 canvas:#ffcc00 Box0030x0024_FFCC00.png"
Shell myFld & CommandIM
End Sub