View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Robin Hammond Robin Hammond is offline
external usenet poster
 
Posts: 79
Default Export picture as gif in Excel

Sandy,

You're welcome, and good idea to put it somewhere else. As I said I hadn't
fully tested it.

Robin Hammond
www.enhanceddatasystems.com
Check out our XspandXL add-in


"Sandy V" wrote in message
...
Robin,

Thanks for providing CopyRangeAsGif.

It works great except the temporary chart sometimes
overlaps part of my selection. Then the "picture" includes
part of this chart (not sure if this only applies to me).

With a few minor changes I've got around this by putting
the temporary chart in another workbook, in particular my
Personal.xls where I'm also putting your code.

Regards,
Sandy

-----Original Message-----
Joe,

As far as I am aware, yes. This is something I came up

with earlier this
week in response to another post. There are other similar

solutions out
there too. I haven't tested this much, but it seems to

work ok.

Sub Test()
CopyRangeAsGif Selection, "c:\temp\test.gif"
End Sub

Sub CopyRangeAsGif(rngCells As Range, strLocation As

String)
Dim chNew As Chart
Dim chObj As ChartObject
Dim lWidth As Long
Dim lHeight As Long
Dim nCounter As Integer
Dim shSource As Worksheet

On Error GoTo 0
If InStr(rngCells.Address, ",") 0 Then
MsgBox "Non contiguous range not permitted"
Exit Sub
End If

With rngCells
For nCounter = 1 To .Columns.Count
lWidth = lWidth + .Columns(nCounter).Width
Next nCounter

For nCounter = 1 To .Rows.Count
lHeight = lHeight + .Rows(nCounter).Height
Next nCounter

End With

Set chNew = Charts.Add

chNew.Location Whe=xlLocationAsObject,

Name:=rngCells.Parent.Name
Set shSource = rngCells.Parent
Set chObj = shSource.ChartObjects

(shSource.ChartObjects.Count)
rngCells.CopyPicture xlScreen, xlPicture

With ActiveChart
.Paste
.ChartArea.Border.LineStyle = 0
.ChartArea.ClearContents
End With

chObj.Width = lWidth + 4
chObj.Height = lHeight + 4
chObj.Chart.Export strLocation, "GIF", False

rngCells.Select
chObj.Delete
End Sub


--
Robin Hammond
www.enhanceddatasystems.com
Check out our XspandXL add-in


"Joe 90" wrote in message
...
I like the way one can export a chart to a gif, is it

possible to export a
picture in Excel. I like the way one can program to

take a "picture of a
range of cells, but want to be able to export this

picture as a gif. is
the
only way to put it in a blank chart?

Thanks




.