您的位置:首页 > 编程语言 > VB

VBA自学应用(14)——使用DTP控件输入日期

2020-02-04 14:28 141 查看

首先我们找到开发工具栏下的ActiveX控件——其他控件,如图所示。

然后找到我们需要的控件

最后用代码控制DTP控件的位置和输入。

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Me.DTPicker1
If Target.Address = Range("a2").Address Then
.Visible = True
.Top = Selection.Top
.Left = Selection.Left
.Height = Selection.Height
.Width = Selection.Width
If Target.Cells(1, 1) <> "" Then
.Value = Target.Cells(1, 1).Value
Else
.Value = Date
End If
Else
.Visible = False
End If

End With
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("a2").Address Then
If Target.Cells(1, 1).Value = "" Then
Me.DTPicker1.Visible = False
End If
End If
End Sub
Private Sub DTPicker1_CloseUp()
ActiveCell.Value = Me.DTPicker1.Value
Me.DTPicker1.Visible = False
End Sub
  • 点赞
  • 收藏
  • 分享
  • 文章举报
star星梦 发布了27 篇原创文章 · 获赞 9 · 访问量 1424 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: