View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
David David is offline
external usenet poster
 
Posts: 1,560
Default Keep Chart-Delete data?

Hi Sharad,
Most excellant. Thank you for your help. "chartShp.CopyPicture xlScreen" was
completely new to me. In fact when I tried to look it up, I can not find it.
Again, thank you.

"Sharad" wrote:

Oh OK, you didn't say you wanted to do it in VBE
Anyway, try following code.

Sub chartPix()
Dim chartShp As Shape, chartName As String, shtName As String
Dim exLeft As Single, exTop As Single
shtName = ActiveSheet.Name
chartName = ActiveChart.Name
chartName = Right(chartName, Len(chartName) - Len(shtName))
chartName = Trim(chartName)
Set chartShp = ActiveSheet.Shapes(chartName)
exLeft = chartShp.Left
exTop = chartShp.Top
chartShp.CopyPicture xlScreen
chartShp.Delete
ActiveSheet.Paste
Selection.Left = exLeft
Selection.Top = exTop

End Sub

If there is no any chart in active sheet or selection is not a chart
then it will give error. I did not add error handling part.

Sharad




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!