Creating an image file

J

Jim

I'm looking for some VBA code that will take an appropriately scaled
matrix and turn it into a saved image file of some sort (e.g., BMP).
Can anyone help?
 
R

Ron de Bruin

Hi Jim

See Harald's code on David's site
http://www.mvps.org/dmcritchie/excel/xl2gif.htm

Or use this small example to save the selection in C:\

Sub Testing()
Application.ScreenUpdating = False
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture

Set ctoTheChartHolder = ActiveSheet.ChartObjects.Add(0, 0, 800, 600)

Set chtTheChart = ctoTheChartHolder.Chart

' Paste the picture onto the chart and
' set an object variable for it
ctoTheChartHolder.Activate
With chtTheChart
.ChartArea.Select
.Paste
Set picThePicture = .Pictures(1)
End With

' Set the picture's properties...
With picThePicture
.Left = 0
.Top = 0
sglWidth = .Width + 7
sglHeight = .Height + 7
End With

' Change the size of the chart object to fit the picture
'better
With ctoTheChartHolder
.Border.LineStyle = xlNone
.Width = sglWidth
.Height = sglHeight
End With
' Export the chart as a graphics file
blnRet = chtTheChart.Export(Filename:="c:\range.gif", _
FilterName:="gif", Interactive:=False)
ctoTheChartHolder.Delete
Application.ScreenUpdating = True
End Sub
 
J

Jim

Thanks Ron. That is some cool stuff. I love it.

But, I guess I wasn't clear about what I wanted.
I'd like to create a gif or a bmp from an array such that each element
of the array contains the color of a single pixel. For instance in a
really simplified example, I'd like to convert the array
{0,63,127,255} into a 1 x 4 image gray-scale image.

Do you have any help for this problem?

Thanks,
Jim
 

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