Embedded image to excel via vba

T

Tim Johnson

As we all know, the export to xls from a report loses all formating. I've
come up with a workaround for all of the information within a report except
for an embedded image. I can place the image into a spreadsheet using code
if it has a static path, but this is less than ideal. Here's the broken code
I've been trying to use:

Dim xlApp as Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim imgPic as Image

Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
Set imgPic = Reports!rptMyReport.Controls!imgLogo

With xlBook.ActiveSheet.Range("a1")
Set myPict = .Parent.Pictures.Insert(imgPic)
End With

This returns Run-Time error 1004: Unable to get the insert property of the
Pictures class.

If I put in a static pathname instead of the imgPic object, all's well, but
for my purposes, this will not work. Excel's vba help file is less than
helpful.

Does anybody have any ideas they'd mind throwing at me?

Thanks in advance,
Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top