to delete a shape

tvmex_210

New Member
Joined
Jan 19, 2011
Messages
11
hi xperts,
newbie here

I have the following sub which is used to create a callout .

======================
Sub callout1()
Dim wsactive As Worksheet
Dim box1 As Shape
Set wsactive = ActiveSheet
Set box1 = wsactive.Shapes.AddCallout(msoCalloutOne, 840, 10, 100, 50)
box1.Callout.Angle = msoCalloutAngle90
box1.TextFrame.Characters.Text = "1. Get details"
End Sub
======================


now i want to create a separate sub (say delcallout1) which when called would delete the callout. i have 3 such callouts to create which should appear and get cleared between many events (mainly commandbutton clicks).at a time only one callout will be active.

is there any way to do this?? plzzz help meee
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Maybe this?

Gary

Code:
Public Sub delcallout1()

Dim oShape As Shape

For Each oShape In ActiveSheet.Shapes

    Debug.Print oShape.Name & vbTab & oShape.AutoShapeType

    If oShape.AutoShapeType = msoShapeLineCallout1NoBorder Then

        oShape.Delete
        
    End If
    
Next oShape

End Sub
 
Upvote 0
thanks a lot for replying......

but unfortunately its not working.:(.... its not throwing any error and also the callout is not getting deleted.

Is there anything i should change in the code which u wrote??
 
Upvote 0
The following line will print a number for the AutoShapeType in the debug window

Code:
Debug.Print oShape.Name & vbTab & oShape.AutoShapeType


Change "msoShapeLineCallout1NoBorder" in the following line to the above mentioned number.

Code:
If oShape.AutoShapeType = msoShapeLineCallout1NoBorder Then

Gary
 
Upvote 0
You could shorten it to the following but that will delete all the shapes on the sheet, not just the "msoCallouts". The "if then" construct just makes it more selective in what it will delete. If you need the selectivity you must use the correct "AutoShapeType" identity code (called an Enum). You can use the number or the name that has been associated (by the developers) with that number.

if you highlight the word "AutoShapeType" in the original sample and press F1 you should get a list of the names.

Gary

Code:
Public Sub delcallout1()

Dim oShape As Shape

For Each oShape In ActiveSheet.Shapes
    oShape.Delete
Next oShape

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,508
Messages
6,179,189
Members
452,893
Latest member
denay

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top