excel 2010:
1. 安装日历控件
下载: 日历控件2007, 安装,
2. 打开excel 2010
---文件-->选项--> 自定义功能区-->开发工具选项前打勾! 在菜单上显示 "开发工具" 选项!
3. 选开发工具 -- > 插入 --> 控件 -- > 选 excel 2007 控件
4. ALT+F11 打开 VBA 窗口, 双击要编写脚本的工作薄(譬如: sheet 1(sheet1)), 粘贴以下代码: 保存并运行该VBA, 转到excel 查看效果!
----------------------------------
Private Sub Calendar1_Click()
ActiveCell = Calendar1.Value
Me.Calendar1.Visible = False
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Target.Column=3 为你要显示日历的列号
If Target.Column = 3 And Target.Row <> 1 And Selection.Rows.Count = 1 And Selection.Columns.Count = 1 Then
Me.Calendar1.Visible = True
Me.Calendar1.Left = Target.Left + Target.Cells.Width + 5
Me.Calendar1.Top = Target.Top
If Target.Value <> "" Then
Me.Calendar1.Value = Target.Value
Else
Me.Calendar1.Value = Now()
End If
Else
Me.Calendar1.Visible = False
End If
End Sub
5. 保存excel 文件: 保存窗口中选择: "启用宏的工作薄" 文件类型! ok!
-------------------------------------------