Board logo

標題: [發問] 刪除控制項 [打印本頁]

作者: caichen3    時間: 2012-4-20 13:12     標題: 刪除控制項

以OLEObjects.Add方法加入Checkbox控制項,
若要刪除工作表內之前加入的Checkbox,該如何寫呢?
Dim OB As OLEObject
For Each OB In ActiveSheet.OLEObjects
   If OB.progID = "Forms.checkbox.1" Then OB.Delete
Next
作者: GBKEE    時間: 2012-4-20 13:28

回復 1# caichen3
Forms.CheckBox.1  大小寫要ㄧ致
作者: caichen3    時間: 2012-4-24 14:14

回復 2# GBKEE

程式碼 "Forms.Checkbox.1"已是大寫但還是無法清除原先的控制項,請大大幫我看看!
Private Sub CommandButton1_Click()
Dim x As Integer
Dim xxx As String
Dim yyy As String
Dim OB As OLEObject

x = UserForm1.ComboBox1.Value
Range("G1").Value = x

For i = 10 To 200
    xxx = i
    Range("A" & xxx).Value = ("")
    Range("B" & xxx).Value = ("")
    Range("C" & xxx).Value = ("")
Next
ActiveSheet.Range("A10:F200").Borders.LineStyle = XILinestyleNone

For j = 1 To x
    yyy = 9 + j
    Range("C" & yyy).Value = j
Next

ActiveSheet.Range("A10:F" & yyy).Borders.LineStyle = xlContinuous
'ActiveSheet.Range("A10:F" & yyy).Borders(xlEdgeBottom).Weight = xlThick
'ActiveSheet.Range("A10:F" & yyy).Borders(xlEdgeRight).Weight = xlThick


For Each OB In ActiveSheet.OLEObjects
   If OB.progID = "Forms.Checkbox.1" Then OB.Delete
Next
n = 1
For Each a In Range("C:C").SpecialCells(xlCellTypeConstants)
   For k = 1 To 3
   
    Select Case k
        Case "1"
        MyStr = n & "功能性需求"
        Case "2"
        MyStr = n & "感官性需求"
        Case "3"
        MyStr = n & "隱藏性需求"
    End Select
   
   With a.Offset(, k)
      Set OB = ActiveSheet.OLEObjects.Add(ClassType:="Forms.Checkbox.1", Left:=.Left, Top:=.Top, Width:=.Width, Height:=.Height)
          OB.Object.Caption = MyStr
          OB.Object.GroupName = n
      
   End With
   Next
  n = n + 1
Next
End Sub
作者: oobird    時間: 2012-4-24 15:07

For Each g In ActiveSheet.Shapes
If g.Name Like "Group*" Then g.Delete
   Next


刪群組
作者: GBKEE    時間: 2012-4-24 16:08

回復 3# caichen3
Forms.CheckBox.1  大小寫要ㄧ致
看看 哪裡不一樣
If OB.progID = "Forms.Checkbox.1" Then OB.Delete
作者: caichen3    時間: 2012-4-24 16:15

回復 5# GBKEE


    感謝大大,原來是上下文"b"不一致 ==
    愧疚啊~~~




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)