第一步,切换设计模式,设置Calendar1的visible为false
也可以设置工作表激活事件,设置Calendar1的visible为false
工作表事件:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If target.count>1 then exit sub
if target.column<> range("H1") then exit sub'假设借用日期为H列
if target.row<3 then exit sub'第3行之前都不处理
Calendar1.Visible = true
end sub
加入日历控件点击事件
Private Sub Calendar1_Click()
Selection.Value = Calendar1.Value
Calendar1.Visible = False
End Sub
Private Sub Calendar1_Click()
ActiveCell = Calendar1.Value
Me.Calendar1.Visible = False
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 你借用日期的那一列列号 Then
Me.Calendar1.Visible = True
Else
Me.Calendar1.Visible = False
End If
End Sub
这个很简单吧
也可以设置工作表激活事件,设置Calendar1的visible为false
加入日历控件
工作表宏:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If target.count<>1 then exit sub
if target.column<>8 then exit sub'假设借用日期为H列
Calendar1.Visible = true
end sub
Private Sub Calendar1_Click()
Selection.Value = Calendar1.Value
Calendar1.Visible = False
End Sub