Paste image from Delphi app into Excel

Hi folks,

I'm fairly new to OLE, so bare with me.  My terminology propbably leaves a lot to be desired :)

I've created an app which basically dumps a heap of formatted data into a speadsheet.  I'd like to include a few bitmaps which I create dynamically as well (but do not want to save them to disk).

Is it possible to stream a TBitmap to Excel use OLE and put it in a given range?

If it's not possible to do via a stream, is it possible to just paste it in (put the bitmap in to the clipboard, then paste it using VBA or something)?

I do not want to save the image to file first.

Any help greatly appreciated!


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The pictures that you want to paste to Excel exist somewhere... don't they? So why saving them again on disk if they already are there... I suggest you to try copying to the clipboard and paste them where you need them. I did not try it yet but it should work with copy/paste.

Also try recording a macro for inserting a picture in excel and from the macro learn how it works and then automate it.
There are a lot of examples out there on how to automate excel

Stuart_JohnsonAuthor Commented:
The picture is generated in-memory by my program, so it doesn't exist anywhere else.

I am trying to work out how to do the copy/paste.  I can not find an example on doing it with a graphic which is why I was asking here.


Hey Stu,

I've done something similar to the second idea you floated but I can't find the code anywhere right now...  Basically I pushed the TBitmap to the Windows clipboard and then had a small bit of VBA that I would call through an Excel OLE object that would pull that down and insert it.... If I remember correctly it wasn't extremely fast and I could never figure out which side it was on but I had my suspicions that it was on the VBA side.

Anyway drop me a line on my hotmail at "gabenick" when you get a chance to let me know how you're doing!  Been a long time since we talked :)

Stuart_JohnsonAuthor Commented:
Hey Gabe dude.  How's it going?

I've sort of got this going with a bit of VBA already, but I'm not overly happy with it.  When the image gets pasted into the cell, I get a warning that the dimensions of the object being pasted is larger than the target cell (or something like that).  I'm trying to find out how to paste without showing the error message more than anything else.

Will drop you an email over the weekend.  I'm as busy as a one legged man in an arse kicking contest at the moment.

Cheers dude,


(PS.  How come you're still GabeinOZ?  You should be GabeInUS now LOL )
Yeah I was thinking about changing it but then I would lose all this mojo I have built up under that name and I'm gonna be back in Oz within the next couple months so its a moot point now :)

Anyway, if I remember correctly I had the same issue you are describing with the error message and what I did was calculated the cell(s) size that I wanted to paste into and pre-selected that area in the VBA before the paste and it didn't throw the message.  Its the same as if you highlight 4 cells and do a copy and then highlight a three cell area and try to paste, it will throw the same error but if you highlight a 4 cell area (or just a single cell) it will let you paste all four copied cells fine.  Hope that helps... :)

Later mate..

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.