View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Joe 90 Joe 90 is offline
external usenet poster
 
Posts: 18
Default Export picture as gif in Excel

Robin

I can see how the code should work but
I am getting "End of statement" errors in 4 places in your code:

With rngCells
For nCounter = 1 To .Columns.Count

HERE! lWidth = lWidth .Columns(nCounter).Width
Next nCounter

For nCounter = 1 To .Rows.Count

HERE! lHeight = lHeight .Rows(nCounter).Height
Next nCounter

End With



and

HERE! chObj.Width = lWidth 4
HERE! chObj.Height = lHeight 4


Is there something I need to activate or do to make this work properly
(I have copied and pasted your code from your message exactly, and tried
removing/adding spaces, parentheses etc to no effect)

Thanks

Joe
"Robin Hammond" wrote in 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