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
Run directly from VB code
- whugemann
- Posts: 289
- Joined: 2011-03-28T07:11:31-07:00
- Authentication code: 8675308
- Location: Münster, Germany 52°N,7.6°E
Re: Run directly from VB code
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
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
Wolfgang Hugemann
Re: Run directly from VB code
Whugemann - you are right
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):

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