excel - 在 VBA 用户表单中,当您输入开始时间和结束时间时,如何在第三个文本框中填充时差
问题描述
我正在准备一个 VBA 用户表单我有一个用于开始时间的文本框和其他用于结束时间的文本框。现在在第三个文本框中我想要将上述两个时间之间的差异作为自动填充的条目。但是我的第三个文本框没有显示时间区别。我发布我的代码以供参考:
Private Sub TxtBxHrs_Change()
Dim sDate As Date, eDate As Date
'Start Date
sDate = DateValue(Me.TxtBxStarttime.Value)
'End Date
eDate = DateValue(Me.TxtBxEndtime.Value)
Me.TxtBxHrs.Value = DateDiff("h", sDate, eDate)
End Sub
解决方案
DateValued
会给你Date
(整数部分)的日期部分。您需要TimeValue
将DateValue
. 尝试
sDate = DateValue(Me.TxtBxStarttime.Value) + TimeValue(Me.TxtBxStarttime.Value)
推荐阅读
- java - 如何从java流中的接口调用MapStruct方法
- python - scipy.optimize_curve_fit 表示无法估计参数的协方差
- javascript - Handlebars 条件样式属性
- python - 从 SQL 字符串中删除关键字
- php - 如何使用 Laravel/PHP 和 MySQL 有效地将数组插入为嵌套集模型
- javascript - Vue 在设置为禁用时重置 INPUT 字段
- php - 如何删除所有空格和新行并制作一个字符串?
- c# - ASP.NET Core 2.2 在 DbContext 中获取 userId
- bash - 卷曲有效载荷在空白处中断
- jenkins - 使用声明性管道的基于提交的作业