2014-04-14 36 views
0

所以下面的代碼是一個開始。我正在嘗試修改下面的代碼,以便在單個工作站的當前會話中找到某個特定日期或之後的預約(針對今天的這個計劃)。然後,我想從約會和描述中提取主題行,並在消息框中顯示它們(以便將來進行錯誤檢查)。如果可能的話,我想添加到這個相同的片段中,可以統計一天內有多少個約會。Outlook Apptment搜索和主題,日期/時間,說明提取

我無法正確設置對象,也無法找到將「我」綁定到Outlook數組中的正確項目的方法。我說「Outlook數組」,因爲在基本代碼中,我有oItems.Item(i),其中我是指定編號的日曆中某個約會的項目。

也許使用除了Item之外的其他東西會更好? 或者更好的是在數組中找到與限制搜索的日期相關的項目位置?

下面是之前找到所需的方法和代碼後,梅德的鏈接

Private Sub FindAppt() 

Dim oItems As Items 
Dim oItemOriginal As AppointmentItem 
Dim Subject As String 
Dim Descript As String 

Set oItems = Outlook.Application.Session.GetDefaultFolder(olFolderCalendar).Items 

    If oItems >= Format(Date, "mmmm dd yyyy") Then 

     Set oItemOriginal = oItems.Item(i) 

    End If 

    With oItemOriginal 

     Subject = .Subject 
     Descript = .FormDescription 

    End With 

    MsgBox (Subject & Description) 

End Sub 

新規範和新方向的舊代碼。此外,新方法應該將這些數組綁定和數組提取分解成單獨的「Subs」?

Sub FindAppt() 

Dim myNameSpace As Outlook.NameSpace 
Dim tdystart As Date 
Dim tdyend As Date 
Dim myAppointments As Outlook.Items 
Dim currentAppointment As Outlook.AppointmentItem 
Dim SubjectArray(50) As Variant 
Dim i As Integer 
Dim DescArray(50) As Variant 
Dim Excl As Excel.Application 

Set myNameSpace = Application.GetNamespace("MAPI") 
    'This line is Bonus, if you're just looking to start your search for today's_ 
    date. 
    tdystart = VBA.Format(Now, "Short Date") 
    'This input works which means a user form with combo boxes will work or user input_ 
    will work as long as user input conforms to VBA date formats. 
    'tdystart = "04/01/2014" 
    'This line is Bonus, if you're just looking for the day after and after_  
    appointments. 
    tdyend = VBA.Format(Now + 1, "Short Date") 
    'tdyend = VBA.Format(tdystart + 5, "Short Date") 
    Set myAppointments = myNameSpace.GetDefaultFolder(olFolderCalendar).Items 
    myAppointments.Sort "[Start]" 
    myAppointments.IncludeRecurrences = True 

Set currentAppointment = myAppointments.Find("[Start] >= """ & tdystart & """ and [Start] <= """ & tdyend & """") 

While TypeName(currentAppointment) <> "Nothing" 

    MsgBox currentAppointment.Subject & " " & currentAppointment.FormDescription 

    While currentAppointment = True 

     For i = 0 To 50 

     SubjectArray(i) = currentAppointment.Subject 
     DescArray(i) = currentAppointment.FormDescription 
     ReDim Preserve SubjectArray(1 To Count + 1) 
     ReDim Preserve DescArray(1 To Count + 1) 

     Next i 

    Wend 

    Set currentAppointment = myAppointments.FindNext 

Wend 

End Sub 

Private Sub Timecard() 

    Set Excl = Excel.Application 
    Dim i As Integer 
    Dim SubjectArray(byRef 50, byValue) As Variant 
    Dim DecArray (byRef,byvalue) 

    With Excl 

     .fPath = ("C:\FilePathName\Book1.xlsx") 

     Excl.Open 

    End With 

    For i = 0 To 50 

     Excl.Application.Activesheet.Range(i, 0) = SubjectArray(i) 
     Excl.Application.Activesheet.Range(i, 1) = DecArray(i) 

    Next 

End Property 

End Sub 
+0

此外,雖然我在這裏我似乎並沒有正確分配的Excel應用程序,因爲我無法獲得該子打開Excel的,我也期待把它放在它自己的子與某種調試/錯誤處理程序來檢查程序是否在任務管理器中打開。 – Ravenous

回答

0

我不知道是什麼行「If oItems >= Format(Date, "mmmm dd yyyy") Then」應該做的事:你在比較的項目與一個String對象。

有關如何檢索特定時間範圍內的項目的示例,請參閱http://msdn.microsoft.com/en-us/library/office/ff866969(v=office.15).aspx

+0

您的鏈接將我引向我錯過的代碼。我知道我正在做一些與oItems變量有關的錯誤。我很感謝你指出If語句中的缺陷。If語句在那裏的原因是限制宏在當前日期之前查找約會的位置。希望我不會懶惰,並且能夠修改發佈的代碼,以便其他人可以使用它。謝謝德米特里! – Ravenous

+0

我進去並使用了MSDN庫中的代碼,這個代碼使我得到了一條新的路徑並添加了更多的問題。我無法打開Excel工作簿,然後我想將「SubjectArray」的索引放在工作簿的單元格中。我已啓用Microsoft Excel 14.0對象庫 – Ravenous

+0

您可能想要啓動一個新線程,因爲它確實與Excel相關。 –