Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Object variable error

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Object variable error

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.)

Anya wrote:

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


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Object variable error

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.)

Anya wrote:

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


--

Dave Peterson

.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Runtime Error '91' Object variable or With block variable not set Alec Coliver Excel Discussion (Misc queries) 2 October 24th 09 02:29 PM
Object Variable Not Set Error on Selection object Jean Excel Worksheet Functions 3 July 24th 06 06:45 PM
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM
Error trap with object variable problem Mike H[_7_] Excel Programming 1 February 6th 04 09:09 AM
Error 91 - Object variable with block variable not set Jim[_35_] Excel Programming 2 November 27th 03 03:34 AM


All times are GMT +1. The time now is 05:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"