Object variable error

  • Thread starter Thread starter Anya
  • Start date Start date
A

Anya

Hello everyone,

I am having trouble creating a macro that will activate a
GIF picture within a chart and delete it. I keep getting
the following error 'object variable or with block
variable not set error'

Can someone help me with this, I'm going nuts. The macro
is below. Any help would be great.

Thanks

ActiveSheet.ChartObjects("Chart 2052").Activate
ActiveChart.Shapes("Picture 20").Select
Selection.Delete
ActiveWindow.Visible = False
 
Your code worked ok for me--if I had a chart named "chart 2052" and a picture in
that chart named "Picture 20".

If you only have one picture in the chart, you could do something like:

Option Explicit
Sub testme01()

Dim myChartObject As ChartObject
Dim myShape As Shape

With ActiveSheet
Set myChartObject = .ChartObjects("chart 2052")
For Each myShape In myChartObject.Chart.Shapes
If myShape.Type = msoPicture Then
'for testing:
'MsgBox myShape.Name
myShape.Delete
'just delete the first one found.
'exit for
End If
Next myShape
End With

End Sub

(if it was chart 2052.)
 
Thank you!!! that works great!!!

-----Original Message-----
Your code worked ok for me--if I had a chart named "chart 2052" and a picture in
that chart named "Picture 20".

If you only have one picture in the chart, you could do something like:

Option Explicit
Sub testme01()

Dim myChartObject As ChartObject
Dim myShape As Shape

With ActiveSheet
Set myChartObject = .ChartObjects("chart 2052")
For Each myShape In myChartObject.Chart.Shapes
If myShape.Type = msoPicture Then
'for testing:
'MsgBox myShape.Name
myShape.Delete
'just delete the first one found.
'exit for
End If
Next myShape
End With

End Sub

(if it was chart 2052.)


--

Dave Peterson
(e-mail address removed)
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top