您的位置:首页 > 其它

Excel使用日历控件

2015-07-28 17:20 363 查看
在导入日历控件后,可以通过如下代码,在Excel的表格中获得对应选择日期的值.
Private Sub DTPicker1_Change()
    Dim sDate As String, sTime As String
    sDate = Format$(DTPicker1.Value, "MM/dd")
    sTime = Format$(DTPicker1.Value, "HH:mm")
    ActiveCell.Value = sDate + vbCrLf + sTime
    If DTPicker1.Visible = 1 Then
        DTPicker1.Visible = False
    End If
End Sub

Private Sub DTPicker1_KeyDown(KeyCode As Integer, ByVal Shift As Integer)
    If KeyCode = 13 Then
    Dim sDate As String, sTime As String
    sDate = Format$(DTPicker1.Value, "MM/dd")
    sTime = Format$(DTPicker1.Value, "HH:mm")
    ActiveCell.Value = sDate + vbCrLf + sTime
    If DTPicker1.Visible = 1 Then
        DTPicker1.Visible = False
    End If
    End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim sDate As String, sTime As String
    With Me.DTPicker1
        If Target.Column = 2 And Target.Count = 1 And Target.Row > 8 Then
            .Visible = True
            .Width = Target.Width + 15
            .Left = Target.Left
            .Top = Target.Top
            .Height = Target.Height
            .Value = Now
        Else
            .Visible = False
        End If
        
    End With
End Sub


来自:http://blog.csdn.net/lan120576664
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: