ImageMagick and Excel

Back from my holidays, with a hard disk full of holiday snaps, and looking for a program to extract the image data saved on the camera, and add comments.  Not liking the offerings provided with the cameras, or any of the free programs I found, I have written my own, using ImageMagick.

ImageMagick is a command line image manipulation program, which has COM+ component, allowing the program functionality to be accessed from VBA.  More details here: ImageMagick COM+ object

My image importer program can be downloded from:, and screenshots are shown below.

To run the program you will need to download and install the ImageMagick software, then in the Visual Basic editor create a reference to the ImageMagickObject 1.0 Type Library, using the Tools-References menu.

The spreadsheet file has only been provided in Excel 2007 format because in earlier versions the file size becomes impracticably large with only a small number of images.

File input list

File input list

Imported thumbnails and file details

Imported thumbnails and file details

This entry was posted in Drawing, Excel, VBA and tagged , , , . Bookmark the permalink.

9 Responses to ImageMagick and Excel

  1. Rick Williams says:

    Where did the comments come in to this?

    Is the end result having the files in the worksheet, and you would type comments below, or did you then export them to something else?


    P.S. I think it’s fantastic that you can bring anything in to Excel that has a COM+ interface. Now I just need to think of things to do with it. 🙂


  2. dougaj4 says:

    Rick – I’m still thinking about the comments!

    I’m thinking maybe I’ll type in comments adjacent to the file names on the first sheet (so I can easily copy down locations etc to adjacent files), then have a macro to copy the comments underneath the other datanext to the appropriate image.

    The other thing I wanted to do was to tag any files that were taken with the camera vertical, and have a macro to rotate the image through 90 degrees.


    • alexb says:


      I’m trying to do something very similar (use imagemagick COM+ with an excel 2007 vba macro) but I’m getting a run-time error ‘-2147418113 (8000ffff)’: Method ‘Identify’ of object IMagicImage’ failed.

      I tried using your code, and got the same error. Did you encounter this? I have checked the ImageMagickObject type library in my VBAProject References.

      Any insights you might be able to provide would be much appreciated.




  3. dougaj4 says:

    Alex – I’m afraid I can’t help. Did you use my Excel file as downloaded, or copy the code into your own spreadsheet?

    If the former I can only suggest there might be a problem with the ImageMagick installation. Maybe someone on the ImageMagick site could help.



  4. jumpjack says:

    If I try to run your project, it fails due to a missing “ImageEffect 1.0 type library” in references. Where do I find it?!?


    • dougaj4 says:

      jumpjack – I haven’t used this spreadsheet for some time, and I’m now also getting “missing ImageEffect 1.0 type library” listed in the references. I’m now using a new computer with Windows 7, so maybe that’s the problem. Are you running Windows 7?

      I don’t know where the ImageEffect 1.0 type library is, and as I didn’t mention it in the original post I assume it didn’t need to be separately installed or enabled under previous Windows versions.

      Anyway, if I find a solution I will post it here.


    • dougaj4 says:

      jumpjack – I installed the latest Imagemagick version, which didn’t seem to help, then unselected the missing ImageEffect 1.0 type library, and it works!

      I have no idea why the reference gets selected, but it seems that it isn’t necessary (at least with Windows 7).


  5. jumpjack says:

    I found this little wiki for VBA and ImageMagick, which helped a lot!

    Here it is a minimal example:

    Private Sub Main_alternate()
    Dim imo As Variant, s As String
    SourceImgPath = “F:\documenti\Progetti\ebook\”
    SourceImgName = “Ebook058.jpg”
    Set imo = CreateObject(“ImageMagickObject.MagickImage.1”)
    s = imo.Convert(“convert”, SourceImgPath & SourceImgName, “-crop”, WIDTH1 & “x” & HEIGHT1 & “+” & TLX1 & “+” & TLY1, SourceImgPath & “left.jpg”)
    s = imo.Convert(SourceImgPath & “left.jpg”, _
    “-distort”, “Perspective”, “0,0,1,1,” & WIDTH1 & “,” & TopOffset1 & “,” & WIDTH1 & “,0,0,” & HEIGHT1 & “,0,” & HEIGHT1 & “,” & WIDTH1 & “,” & BottomOffset1 & “,” & WIDTH1 & “,” & HEIGHT1, _
    SourceImgPath & “Left-ok.jpg”)
    End Sub

    The example shows how to “convert” commandline for “convert” function into VBA code;
    the DOS batch line:

    becomes in VBA:
    s = imo.Convert(“convert”, SourceImgPath & SourceImgName, “-crop”, WIDTH1 & “x” & HEIGHT1 & “+” & TLX1 & “+” & TLY1, SourceImgPath & “left.jpg”)

    After assigning varianles, printing first line results in:
    convert F:\documenti\Progetti\ebook\Ebook058.JPG -crop 670×1293+580+30 F:\documenti\Progetti\ebook\left.jpg

    Printing second line results in:
    F:\documenti\Progetti\ebook\Ebook058.jpg -crop 670×1293+580+30 F:\documenti\Progetti\ebook\left.jpg

    Which is (of course) exactly the same.

    The DOS batch line:
    convert %SOURCEIMGPATH%left.jpg -virtual-pixel white -distort Perspective “0,0,1,1 %WIDTH1%,%TopOffset1%,%WIDTH1%,0 0,%HEIGHT1%,0,%HEIGHT1% %WIDTH1%,%BottomOffset1%,%WIDTH1%,%HEIGHT1%” %SOURCEIMGPATH%left-ok.jpg

    becomes in VBA:
    s = imo.Convert(SourceImgPath & “left.jpg”, “-distort”, “Perspective”, “0,0,1,1,” & WIDTH1 & “,” & TopOffset1 & “,” & WIDTH1 & “,0,0,” & HEIGHT1 & “,0,” & HEIGHT1 & “,” & WIDTH1 & “,” & BottomOffset1 & “,” & WIDTH1 & “,” & HEIGHT1, SourceImgPath & “Left-ok.jpg”)

    Printing first:
    convert F:\documenti\Progetti\ebook\left.jpg -virtual-pixel white -distort Perspective “0,0,1,1 670,165,670,0 0,1293
    ,0,1293 670,1234,670,1293” F:\documenti\Progetti\ebook\left-ok.jpg

    Printing second:
    F:\documenti\Progetti\ebook\left.jpg -virtual-pixel white -distort Perspective 0,0,1,1,670,165,670,0,0,1293,0,1293,670,1234,670,1293 F:\documenti\Progetti\ebook\Left-ok.jpg

    Please note that ImageMagick does not care if you use “,” or ” ” as a separator.

    To get it working, I had to manually register ImageMagick library using
    regsvr32 ImageMagickObject.dll , although I installed the .MSI version specifying I wanted the COM object to be installed.


  6. Pingback: Daily Download 12: ImageMagick and Excel | Newton Excel Bach, not (just) an Excel Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.