我在Excel中创建一个用户窗体,它将在我的Outlook日历中创建一个约会。除了开始和结束时间以外,一切都在工作。下面是我的代码,其中DTPicker1是约会的日期,DTPicker2和DTPicker3分别是开始和结束时间。它们采用dtpTime格式。约会是在正确的日期和主题上创建的,除了时间之外,一切都正常工作。不知道我应该如何解决它。任何帮助表示赞赏。谢谢!Excel VBA - 如何在时间格式中格式化用户窗体文本框
Private Sub CommandButton1_Click()
Dim olApp As Outlook.Application
Dim olAppItem As Outlook.AppointmentItem
Dim r As Long
On Error Resume Next
Worksheets("Sheet1").Activate
Set olApp = GetObject("", "Outlook.Application")
On Error GoTo 0
If olApp Is Nothing Then
On Error Resume Next
Set olApp = CreateObject("Outlook.Application")
On Error GoTo 0
If olApp Is Nothing Then
MsgBox "Outlook is not available!"
Exit Sub
End If
End If
Dim mysub, myStart, myEnd
mysub = TextBox1
myStart = DTPicker1 & DatePicker2
myEnd = DTPicker1 & DatePicker3
Set olAppItem = olApp.CreateItem(olAppointmentItem) 'creates a new appointment
With olAppItem
'set default appointment values
.Location = ""
.Body = ""
.ReminderSet = True
.BusyStatus = olFree
.RequiredAttendees = ""
On Error Resume Next
.Start = myStart
.End = myEnd
.Subject = TextBox1
.Attachments.Add ("c:\temp\somefile.msg")
.Location = ""
.Body = ""
.ReminderSet = True
.BusyStatus = olBusy
.Categories = "Orange Category"
On Error GoTo 0
.Save 'saves the new appointment to the default folder
End With
Set olAppItem = Nothing
Set olApp = Nothing
MsgBox "Done !"
End Sub
正如您所认识的,内置文本框控件不会执行此操作。 什么你可能是响应文本框更改事件 获取文本和相应的代码 – dgorti
格式我完全忘了UserForm中的DatePicker框可以更改为时间格式的格式,所以我打算使用但现在也不行。我想这可能是我编写的代码,而不是格式。我将用我的所有代码编辑我的问题。 – gluc7
@ gluc7我看不到你在哪儿'Dim myStart As Date'?它应该是'myStart = DTPicker1.value'。什么是'myStart = DTPicker1&DatePicker2'假设是?你想把这些日期加在一起吗?究竟是什么? –