如何在Excel2007中实现双击单元格,弹出日历,选择日期自动填充?

2024-12-04 05:21:22
推荐回答(1个)
回答1:

按alt+F11调出代码输入界面,先双击左边表格名,在右边复制以下代码:
Private Sub Calendar1_Click()
ActiveCell.Value = Calendar1.Value
Calendar1.Visible = False
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count = 1 Then
If Target.Column = 1 Then '这是A列,如果要B列则改为2,其他同理.
With Calendar1
If Target <> "" Then
.Value = Target
Else
.Value = Date
End If
.Visible = True
.Top = Target.Top
.Left = Target.Left
End With
Else
Calendar1.Visible = False
End If
End If
End Sub

可以实现在A列选中单元格出现日历.如果要更改其他单元格按上面说明.