ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Moving/deleting pictures within charts via macros (https://www.excelbanter.com/excel-programming/314242-moving-deleting-pictures-within-charts-via-macros.html)

Walshy[_3_]

Moving/deleting pictures within charts via macros
 
Hi,

Could you please help me...

I have a chart on excel and a macro is run each day to produce or update
this chart.

problem I am having is within the chart I have a picture (A traffic light) I
tried to record a macro that selects the picture, deletes it then gets the
picture from somewhere else (Red, amber or green light depending)on the same
sheet and pastes it onto the chart. Now it gets the picture fine and pastes
it onto the chart but it wont do the delete part ??? or it wont let me select
the picture and move it on the chart ??? (Think the prob is actually
selecting the picture within the chart ??? Not sure why this is, could you
please help me ?????

this is the code that Dont work...:
'ActiveSheet.ChartObjects("Chart 55").Activate
error here - 'ActiveChart.Shapes("Picture 2").Select
'Selection.Delete

Thanks



Sean[_11_]

Moving/deleting pictures within charts via macros
 
What if, instead of selecting/deleting you used variables to refer to
the various parts. I think that pictures are stored on the Chart and NOT
the ChartObject and below are some examples you what you might need.

----
Sean
"Just press the off switch, and go to sleep!"


'----------------------------------------------
'----------------------------------------------
Dim ch As Excel.Chart, shp As Excel.Shape, shpr As Excel.ShapeRange

' this is the chart we will be working with
Set ch = ActiveSheet.ChartObjects("Chart 55").Chart

' add a new picture from a file
Set shp = ch.Pictures.Insert(file_name).ShapeRange(1)

' delete the picture we have just added
shp.Delete

' delete a specific picture from our chart
ch.Shapes("Picture 2").Delete

' delete ALL the pictures from our chart
ch.Shapes.SelectAll
Set shpr = Selection.ShapeRange
shpr.Delete

'----------------------------------------------
'----------------------------------------------


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


All times are GMT +1. The time now is 06:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com