Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Creating an image file

10 views
Skip to first unread message

Jim

unread,
Jun 11, 2006, 8:01:46 AM6/11/06
to
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?

Ron de Bruin

unread,
Jun 11, 2006, 8:09:50 AM6/11/06
to
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


--
Regards Ron De Bruin
http://www.rondebruin.nl

"Jim" <jvbe...@aol.com> wrote in message news:1150027306....@g10g2000cwb.googlegroups.com...

Jim

unread,
Jun 11, 2006, 11:47:00 AM6/11/06
to
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

Ron de Bruin

unread,
Jun 11, 2006, 12:49:53 PM6/11/06
to
> Do you have any help for this problem?

No, sorry

--
Regards Ron De Bruin
http://www.rondebruin.nl

"Jim" <jvbe...@aol.com> wrote in message news:1150040820....@c74g2000cwc.googlegroups.com...

0 new messages