2012-11-26 66 views
0

我正在嘗試從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用戶窗體的文本字段

感謝

回答

0

TIMEVALUE似乎並沒有讓您包括日期,只有一天的時間。例如,如果您使用以下格式設置開始和結束時間,那麼它確實有效。

OLAppointment.Start = #11/26/2012 1:00:00 PM# 
OLAppointment.End = #11/26/2012 2:00:00 PM#