Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.26 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Deleting a collections of VBA buttons
  2. Sub CreateAddButton(rng As Range)
  3.     Dim btn As Button
  4.     With Worksheets("User")
  5.         Set btn = .Buttons.Add(rng.Left, rng.Top, rng.width, rng.Height)
  6.         With btn
  7.            .name = "Add"
  8.            .Caption = "Add Column"
  9.            .OnAction = "CreateVariable"
  10.         End With
  11.     End With
  12. End Sub
  13.        
  14. .Name = "Add_||ForDeletion"
  15.        
  16. Sub TesMe()
  17.     Call CreateAddButton([a2])
  18. End Sub
  19.  
  20. Sub CreateAddButton(rng As Range)
  21.     Dim btn As Button
  22.     With Worksheets("User")
  23.         Set btn = .Buttons.Add(rng.Left, rng.Top, rng.Width, rng.Height)
  24.         With btn
  25.             .Name = "Add"
  26.             .Caption = "Add Column"
  27.             .OnAction = "CreateVariable"
  28.             .ShapeRange.AlternativeText = "MyCollection"
  29.         End With
  30.     End With
  31. End Sub
  32.  
  33.  
  34. Sub GetMyButtons()
  35.     Dim btns As Object
  36.     Dim lngRow As Long
  37.     Set btns = Sheets("User").Buttons
  38.     For lngRow = btns.Count To 1 Step -1
  39.         If btns(lngRow).ShapeRange.AlternativeText = "MyCollection" Then
  40.             MsgBox "Found one", vbCritical
  41.             btns(lngRow).Delete
  42.         End If
  43.     Next
  44. End Sub
  45.        
  46. Sub deleteButtons()
  47. Dim btn As Shape
  48.  
  49. For Each btn In ActiveSheet.Shapes
  50.     If btn.AutoShapeType = msoShapeStyleMixed Then btn.Delete
  51. Next
  52.  
  53. End Sub