我對 VBA 完全陌生,所以如果這似乎是一個愚蠢的問題,我很抱歉。我正在嘗試將“其他日期:”旁邊的文本框設定為只有在選擇“其他日期”按鈕時才能在其中寫入。

到目前為止,這就是我所擁有的顯然不起作用的東西:)
Private Sub otherDateTextBox_Change()
If Me.todayButton.Value = True Then
Me.otherDateTextBox.Locked = True
ElseIf Me.tomorrowButton.Value = True Then
Me.otherDateTextBox.Locked = True
ElseIf Me.otherDateButton.Value = True Then
Me.otherDateTextBox.Locked = False
End If
End Sub
任何幫助,將不勝感激
uj5u.com熱心網友回復:
您使用了錯誤的事件,因為 的狀態otherDateTextBox由 的值決定,otherDateButton因此您應該使用 的Change事件otherDateButton。
您可以使用該Enabled屬性“鎖定”文本框,使其不可選擇且不可編輯(將顯示為灰色)
Private Sub otherDateButton_Change()
otherDateTextBox.Enabled = otherDateButton.Value
End Sub
uj5u.com熱心網友回復:
使用以下代碼在加載/激活表單時禁用 TextBox
Private Sub UserForm_Activate()
TextBox1.Enabled = False
End Sub
所以默認情況下它將被禁用。之后添加以下代碼以在 Option1 為 True 或 False 時啟用 TextBox。
Private Sub OptionButton1_Change()
If OptionButton1.Value = True Then
TextBox1.Enabled = True
Else
TextBox1.Enabled = False
End If
End Sub
您也可以在禁用文本框之前清除文本框中的文本
Private Sub OptionButton1_Change()
If OptionButton1.Value = True Then
TextBox1.Enabled = True
Else
TextBox1.Text = ""
TextBox1.Enabled = False
End If
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/338664.html
