PDA

View Full Version : Solved: Saving Bitmap from Excel



FISHBONE
04-08-2006, 02:55 PM
Hi All:

I am trying to save jpg image as a bitmap from excel.

I don't know if it can be done within excel or if Irfanview is needed.

Is there code to do it within Excel or does another picture editor need to be opened?

Please include the selection code just as referance.

Thanks

johnske
04-10-2006, 03:42 AM
Hi FISHBONE,

You can't export pictures directly from excel, but you can paste your picture onto a (blank) chart and export the chart as a picture.

Here's the general idea (see attachment also) exporting in jpg format, if you want it exported in bitmap format just change the code from .jpg to .bmp...

(NOTE: You'll need excel 2000 or greater to run this)

PS: You're not restricted to just pictures here, you can also select text-boxes, shapes, buttons, etc. and export an image of them.
Option Explicit
Sub ExportMyPicture()
Dim MyChart As String, MyPicture As String
Dim PicWidth As Long, PicHeight As Long

Application.ScreenUpdating = False
On Error GoTo Finish
MyPicture = Selection.Name
With Selection
PicHeight = .ShapeRange.Height
PicWidth = .ShapeRange.Width
End With

Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
Selection.Border.LineStyle = 0
MyChart = Selection.Name & " " & Split(ActiveChart.Name, " ")(2)

With ActiveSheet
With .Shapes(MyChart)
.Width = PicWidth
.Height = PicHeight
End With

.Shapes(MyPicture).Copy

With ActiveChart
.ChartArea.Select
.Paste
End With

.ChartObjects(1).Chart.Export Filename:="MyPic.jpg", FilterName:="jpg"
.Shapes(MyChart).Cut
End With

Application.ScreenUpdating = True
Exit Sub

Finish:
MsgBox "You must select a picture"
End Sub

FISHBONE
04-11-2006, 08:53 PM
Johnske,

Thank you very much for your help. I have been trying to do this with sendkeys to paint but it is confusing.

Your method works great.

I was hoping someone would respond thanks again.

FISHBONE

johnske
04-11-2006, 09:02 PM
So I assume we can mark this solved? :)