私は一連のユーザーフォームを持っており、アンケートを作成しています。各ユーザーフォームは、いくつかのオプションボタン/チェックボックスで構成されています。プログラムは正常に動作します。ただし、(Excel を終了せずに) プログラムを再起動すると、前のユーザーと同じようにラジオボタンとチェックボックスが入力されます。
モジュールを呼び出すために、ユーザーフォームの初期化ごとに試しました:
Option base 0
Sub clearBtns()
Dim optBtn(10) As Variant
optBtn(0) = "optA"
optBtn(1) = "optB"
optBtn(2) = "optC"
optBtn(3) = "optD"
optBtn(4) = "optE"
optBtn(5) = "chkA"
optBtn(6) = "chkB"
optBtn(7) = "chkC"
optBtn(8) = "chkD"
optBtn(9) = "chkE"
optBtn(10) = "chkF"
Dim cnt As Integer
For cnt = 0 To 10
If Not optBtn(cnt) Is Nothing Then
optBtn(cnt).Value = False
End If
Next cnt
End Sub
残念ながら、これは機能しません (エラー 424、オブジェクトが必要です)。それはおそらくこの部分と関係があります:
If Not optBtn(cnt) Is Nothing Then
これを行うには、もっと簡単な方法が必要です。追加情報: 各フォームが完成したら、次を使用します。
Me.Hide
form_x.Show
最後の形式は異なります。
Unload Me
多分問題がありますか?
詳細については、次のとおりです。
Option Base 0
Public Sub clearBtns()
Dim optBtn(10) As Variant
optBtn(0) = "optA"
optBtn(1) = "optB"
optBtn(2) = "optC"
optBtn(3) = "optD"
optBtn(4) = "optE"
optBtn(5) = "chkA"
optBtn(6) = "chkB"
optBtn(7) = "chkC"
optBtn(8) = "chkD"
optBtn(9) = "chkE"
optBtn(10) = "chkF"
Dim formArray(27) As Variant
formArray(0) = "page1_1"
formArray(1) = "page1_2"
formArray(2) = "page1_3"
formArray(3) = "page2_1"
formArray(4) = "page2_2"
formArray(5) = "page2_3"
formArray(6) = "page3_1"
formArray(7) = "page3_2"
formArray(8) = "page3_3"
formArray(9) = "page4_1"
formArray(10) = "page4_2"
formArray(11) = "page4_3"
formArray(12) = "page5_1"
formArray(13) = "page6_1"
formArray(14) = "page6_2"
formArray(15) = "page6_3"
formArray(16) = "page7_1"
formArray(17) = "page7_2"
formArray(18) = "page7_3"
formArray(19) = "page8_1"
formArray(20) = "page8_2"
formArray(21) = "page8_3"
formArray(22) = "page9_1"
formArray(23) = "page9_2"
formArray(24) = "page9_3"
formArray(25) = "page10_1"
formArray(26) = "page10_2"
formArray(27) = "page10_3"
Dim cnt As Integer
Dim fCnt As Integer
For fCnt = 0 To 27
For cnt = 0 To 10
On Error Resume Next
formArray(fCnt).Controls(optBtn(cnt)).Value = False
Next cnt
Next fCnt
End Sub
上記のコードは機能しません。
Public Sub clearBtns()
Dim optBtn(10) As Variant
optBtn(0) = "optA"
optBtn(1) = "optB"
optBtn(2) = "optC"
optBtn(3) = "optD"
optBtn(4) = "optE"
optBtn(5) = "chkA"
optBtn(6) = "chkB"
optBtn(7) = "chkC"
optBtn(8) = "chkD"
optBtn(9) = "chkE"
optBtn(10) = "chkF"
Dim cnt As Integer
For cnt = 0 To 10
On Error Resume Next
page1_1.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page1_2.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page1_3.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page2_1.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page2_2.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page2_3.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page3_1.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page3_2.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page3_3.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page4_1.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page4_2.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page4_3.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page5_1.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page6_1.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page6_2.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page6_3.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page7_1.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page7_2.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page7_3.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page8_1.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page8_2.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page8_3.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page9_1.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page9_2.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page9_3.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page10_1.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page10_2.Controls(optBtn(cnt)).Value = False
Next cnt
cnt = 0
For cnt = 0 To 10
On Error Resume Next
page10_3.Controls(optBtn(cnt)).Value = False
Next cnt
On Error GoTo 0
End Sub
上記のコードは機能しますが、より多くのコードが必要になり、非常に非効率的です。