Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default ActiveSheet.Shapes

Hi NG,

I have the following code that removes my commandbuttons on "save", it's a
XLT file with
3 sheets, my problem is that it only removes the commandbuttons on the
active sheet and
i need it to remove the commandbuttons on all 3 sheets in my workbook.

I can't seem to find anything were you can do it on all sheets??

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
'----------------------------------------------------------------
'Sub RemoveShapes()
'----------------------------------------------------------------
Dim shp As Shape
Dim sTopLeft As String
Dim fOK As Boolean

For Each shp In ActiveSheet.Shapes

fOK = True

sTopLeft = ""
On Error Resume Next
sTopLeft = shp.TopLeftCell.Address
'Autofilter and Data Validation dropdowns
'don't seem to have a topleftcell address.
On Error GoTo 0

If shp.Type = msoFormControl Then
If shp.FormControlType = xlDropDown Then
If sTopLeft = "" Then
'keep it
fOK = False
End If
End If
End If

If fOK Then
shp.Delete
End If

Next shp

End Sub

AHA.
Ole


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default ActiveSheet.Shapes

If you're just getting rid of commandbuttons from the control toolbox toolbar,
it may be better to just go after them:

Option Explicit
Sub testme()

Dim OLEObj As OLEObject
Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
For Each OLEObj In wks.OLEObjects
If TypeOf OLEObj.Object Is MSForms.CommandButton Then
OLEObj.Delete
End If
Next OLEObj
Next wks

End Sub



ole_ wrote:

Hi NG,

I have the following code that removes my commandbuttons on "save", it's a
XLT file with
3 sheets, my problem is that it only removes the commandbuttons on the
active sheet and
i need it to remove the commandbuttons on all 3 sheets in my workbook.

I can't seem to find anything were you can do it on all sheets??

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
'----------------------------------------------------------------
'Sub RemoveShapes()
'----------------------------------------------------------------
Dim shp As Shape
Dim sTopLeft As String
Dim fOK As Boolean

For Each shp In ActiveSheet.Shapes

fOK = True

sTopLeft = ""
On Error Resume Next
sTopLeft = shp.TopLeftCell.Address
'Autofilter and Data Validation dropdowns
'don't seem to have a topleftcell address.
On Error GoTo 0

If shp.Type = msoFormControl Then
If shp.FormControlType = xlDropDown Then
If sTopLeft = "" Then
'keep it
fOK = False
End If
End If
End If

If fOK Then
shp.Delete
End If

Next shp

End Sub

AHA.
Ole


--

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
excel document with shapes on it but the shapes do not print [email protected] Excel Worksheet Functions 2 October 22nd 09 06:17 PM
Naming Auto Shapes and Creating new Shapes AL2000 Excel Discussion (Misc queries) 3 September 10th 07 04:12 AM
When drawing shapes in excel the shapes keep disappearing Tape Excel Discussion (Misc queries) 1 October 6th 06 04:23 PM
How can i get more 3D shapes for Auto shapes in excel? Ajey Excel Discussion (Misc queries) 0 March 3rd 05 09:53 AM
Shapes In ActiveSheet Tommi[_2_] Excel Programming 5 December 2nd 03 02:02 PM


All times are GMT +1. The time now is 03:51 PM.

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

About Us

"It's about Microsoft Excel"