Export autoshape as picture using VBA? (object doesn't support met

K

ker_01

Excel 2003, although I'd like my code to work in 2007 as well, in case I
up(?)grade.

I'm trying to export an autoshape as a picture (code below). The last line
returns a 438 error; "object does not support this property or method". I
welcome any suggestions on how to adjust the code to export an autoshape as
an image.

Overall plan- because you might have other good ideas for me to consider- I
want to use some 'custom' colors without using the color palette, but Excel
doesn't like that idea. At this point, I am trying to use only the last
custom color index; set it to my custom color, set the autoshape to that
color, save the autoshape as a picture; then change the custom color palette
back to what it was before I used it. Last, I import my autoshape as an
image, thereby retaining my custom color without requiring the ongoing use of
the palette.

My next step will be to import the "autoshape" image and try to place it
exactly where the autoshape was (and then delete the autoshape). I also need
to ensure that my image's background is transparent so that I can overlap
images and have it look the same as overlapped autoshapes.

Sub ExportShapeAsPicture()
Dim IShape As Shape
Err.Number = 0
On Error Resume Next

Set IShape = ActiveWorkbook.ActiveSheet.Shapes("AutoShape 9133")
If IShape Is Nothing Or Err.Number <> 0 Then
MsgBox "Whoops, no shape by this name"
Exit Sub
End If

ShapeName = "test_i1"

UsePath = ActiveWorkbook.Path & "\" & ShapeName & ".gif"
On Error GoTo 0
IShape.Export FileName:=UsePath, FilterName:="GIF"

End Sub
 
P

Peter T

The Export method only works with charts, you can place (or paste) your
shape on an empty chart (no border etc) and Export the chart.

It's also possible to copy the shape, get its bmp or metafile format from
the clipboard and save to file (API stuff)

I don't quite follow the overall objective though and wonder why you need to
export the shape as an image, only to reimport it back. Concerning colours,
even in pre Excel 2007 you are not confined to the palette, eg -

shp.Fill.ForeColor.RGB = RGB(50, 150, 250)

In all versions you can also give your shape a degree of transparency from
opaque to completely transparent.

Regards,
Peer T
 

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