1
我正在使用大約10個獨立的Excel工作簿和一個跟蹤工作簿。我在所有10個工作簿上都有清晰的按鈕,但想要在跟蹤工具上清除所有按鈕,這樣我的員工就不必打開每個工作簿來清除其內容。在每個工作簿的VBA代碼如下所示:使用清除按鈕清除單獨的工作簿中的單元格,複選框和組合框
Private Sub CommandButton1_Click()
Sheet1.ComboBox172.Text = "-"
Sheet1.ComboBox174.Text = "-"
Sheet1.ComboBox175.Text = "-"
Sheet1.CheckBox1.Value = False
Sheet1.CheckBox2.Value = False
Sheet1.CheckBox3.Value = False
Sheet1.TextBox1.Text = ""
Sheet1.TextBox2.Text = ""
Sheet1.TextBox3.Text = ""
Sheet1.TextBox4.Text = ""
Sheet1.TextBox5.Text = ""
Sheet1.TextBox6.Text = ""
Sheet1.TextBox7.Text = ""
Sheet1.TextBox9.Text = ""
Sheet1.TextBox10.Text = ""
Sheet1.TextBox11.Text = ""
Sheet1.TextBox12.Text = ""
Sheet1.Range("D9:D21").Value = "-"
Sheet1.Range("D25:D36").Value = "-"
Sheet1.Range("D42:D52").Value = "-"
Sheet1.Range("D56:D60").Value = "-"
Sheet1.Range("D65:D67").Value = "-"
Sheet1.Range("D71:D76").Value = "-"
Sheet1.Range("D80:D83").Value = "-"
Sheet1.Range("D87:D91").Value = "-"
Sheet1.Range("D95:D100").Value = "-"
Sheet1.Range("D104:D106").Value = "-"
Sheet1.Range("L9:L20").Value = "-"
Sheet1.Range("L25:L35").Value = "-"
Sheet1.Range("L42:L52").Value = "-"
Sheet1.Range("L56:L61").Value = "-"
Sheet1.Range("L65:L67").Value = "-"
Sheet1.Range("L71:L75").Value = "-"
Sheet1.Range("L80:L82").Value = "-"
Sheet1.Range("L87:L90").Value = "-"
Sheet1.Range("L95:L100").Value = "-"
Dim Shp As Shape
For Each Shp In Sheet1.Shapes
If Not (Shp.Type = msoOLEControlObject Or Shp.Type = msoFormControl Or Shp.Type = msoPicture) Then Shp.Delete
Next Shp
For Each Shp In Sheet2.Shapes
If Not (Shp.Type = msoOLEControlObject Or Shp.Type = msoFormControl Or Shp.Type = msoPicture) Then Shp.Delete
Next Shp
Sheet2.ComboBox2.Text = "-"
Sheet2.ComboBox3.Text = "-"
Sheet2.ComboBox4.Text = "-"
Sheet2.CheckBox1.Value = False
Sheet2.CheckBox2.Value = False
Sheet2.CheckBox3.Value = False
Sheet2.CheckBox4.Value = False
Sheet2.CheckBox5.Value = False
Sheet2.CheckBox8.Value = False
Sheet2.CheckBox9.Value = False
Sheet2.CheckBox10.Value = False
Sheet2.CheckBox11.Value = False
Sheet2.Range("F9:F9").Value = 0
Sheet2.Range("F11:F11").Value = 0
Sheet2.Range("F15:F15").Value = 0
Sheet2.Range("F17:F17").Value = 0
Sheet2.Range("F21:F21").Value = 0
Sheet2.Range("F23:F23").Value = 0
Sheet2.Range("F27:F27").Value = 0
Sheet2.Range("F29:F29").Value = 0
Sheet2.Range("F35:F35").Value = 0
Sheet2.Range("F37:F37").Value = 0
Sheet2.Range("F39:F39").Value = 0
Sheet2.Range("F45:F45").Value = 0
Sheet2.Range("F47:F47").Value = 0
Sheet2.Range("F53:F53").Value = 0
Sheet2.Range("F55:F55").Value = 0
Sheet2.Range("K35:K35").Value = 0
Sheet2.Range("J9:M9").ClearContents
Sheet2.Range("J15:M15").ClearContents
Sheet2.Range("J21:M21").ClearContents
Sheet2.Range("J27:M27").ClearContents
Sheet3.ComboBox1.Text = "-"
Sheet3.ComboBox2.Text = "-"
Sheet3.ComboBox3.Text = "-"
Sheet3.ComboBox4.Text = "-"
Sheet3.ComboBox6.Text = "-"
Sheet3.TextBox1.Text = ""
Sheet3.TextBox2.Text = ""
Sheet3.TextBox3.Text = ""
Sheet3.TextBox5.Text = ""
Sheet3.TextBox6.Text = ""
Sheet3.CheckBox1.Value = False
Sheet3.CheckBox2.Value = False
Sheet3.CheckBox3.Value = False
Sheet3.CheckBox4.Value = False
Sheet3.CheckBox5.Value = False
Sheet3.CheckBox6.Value = False
Sheet3.CheckBox7.Value = False
Sheet3.CheckBox8.Value = False
Sheet3.CheckBox9.Value = False
Sheet3.CheckBox10.Value = False
Sheet3.CheckBox11.Value = False
Sheet3.CheckBox12.Value = False
Sheet3.CheckBox13.Value = False
Sheet3.CheckBox14.Value = False
Sheet3.CheckBox15.Value = False
Sheet3.CheckBox16.Value = False
Sheet3.CheckBox17.Value = False
Sheet3.CheckBox18.Value = False
Sheet3.CheckBox19.Value = False
Sheet3.CheckBox20.Value = False
Sheet3.CheckBox21.Value = False
Sheet3.CheckBox22.Value = False
Sheet3.CheckBox23.Value = False
Sheet3.CheckBox24.Value = False
Sheet3.CheckBox25.Value = False
Sheet3.CheckBox26.Value = False
Sheet3.CheckBox27.Value = False
Sheet3.CheckBox28.Value = False
Sheet3.CheckBox29.Value = False
Sheet3.CheckBox30.Value = False
Sheet3.CheckBox31.Value = False
Sheet3.CheckBox32.Value = False
Sheet3.CheckBox33.Value = False
Sheet3.CheckBox34.Value = False
Sheet3.CheckBox35.Value = False
Sheet3.CheckBox36.Value = False
Sheet3.CheckBox37.Value = False
Sheet3.CheckBox38.Value = False
Sheet3.CheckBox39.Value = False
Sheet3.CheckBox41.Value = False
Sheet3.CheckBox43.Value = False
Sheet3.Range("C9:C9").Value = ""
Sheet3.Range("C11:C11").Value = ""
Sheet3.Range("H9:H9").Value = ""
Sheet3.Range("H11:H11").Value = ""
Sheet3.Range("L9:L9").Value = ""
Sheet3.Range("L11:L11").Value = ""
Sheet3.Range("L17:N17").Value = 0
Sheet3.Range("L18:N18").Value = 0
Sheet3.Range("L19:N19").Value = 0
Sheet3.Range("L20:N20").Value = 0
End Sub
我有上的跟蹤片引用任何其它工作簿的清除按鈕的問題。
爲什麼不使用循環來減少重複代碼? –
將代碼插入Excel仍然相當新...大部分代碼都是我在網上找到的東西 – Guaca24