我正在尝试从VBA宏生成约会并将其放入Outlook中的日历中。我的代码在下面......
Sub CommandButton1_Click()
Const olAppointmentItem As Long = 1
Dim olapp As Object
Dim OLNS As Object
Dim OLAppointment As Object
On Error Resume Next
Set olapp = GetObject(, "Outlook.Application")
If olapp Is Nothing Then Set olapp = CreateObject("Outlook.Application")
On Error GoTo 0
If Not olapp Is Nothing Then
Set OLNS = olapp.GetNamespace("MAPI")
OLNS.Logon
Set OLAppointment = olapp.CreateItem(olAppointmentItem)
OLAppointment.Subject = "Request for Leave"
OLAppointment.Start = TimeValue(TextBox7.Text)
OLAppointment.End = TimeValue(TextBox10.Text)
OLAppointment.Location = "Leave"
OLAppointment.Body = "Request for Leave"
OLAppointment.Save
'Set OLAppointment = olapp.Move(olfolder)
Set OLAppointment = Nothing
Set OLNS = Nothing
Set olapp = Nothing
End If
End Sub
问题是约会的日期是在'星期六30/12/1899'开始,并且只持续半小时我需要它在两个日期之间的持续时间作为全天约会整个,(开始日期:TextBox7)(结束日期:TextBox10)。
另一个问题是我如何将此请求发送给某人?
约会详细信息来自Excel UserForm的文本字段
由于
答案 0 :(得分:0)
TimeValue似乎不允许您包含日期,只包括一天中的时间。例如,如果您使用以下格式设置开始和结束时间,那么它确实有效。
OLAppointment.Start = #11/26/2012 1:00:00 PM#
OLAppointment.End = #11/26/2012 2:00:00 PM#