2015-11-20 39 views
0

我找到了一些可行的代碼來查找和打印,以記錄給定日期範圍內的所有約會開始日期和主題。這很好。Outlook日曆VBA代碼查找所有約會中的某個字符串

我所追求的是一種輸出以下內容的方式: 開始日期/時間;學科; 「Line of Text of Line of Appointment」,Line X

但是僅限於數據範圍內約會正文中也有一定字符串的約會。

這是我使用的代碼... 昏暗oAppt作爲Outlook.AppointmentItem MyFile.WriteLine的一部分(oAppt.Start & 「;」 & oAppt.Subject)

我沒找到在oAppt.Body上用於搜索的任何方法或函數。下面是我的VBA腳本的全部代碼,因爲它代表現在:使用VBCR一個數組,其中每行是一個元素

Sub FindAppts() 
    Dim daStart, daEnd As Date 
    Dim oCalendar As Outlook.Folder 
    Dim oItems As Outlook.Items 
    Dim oItemsInDateRange As Outlook.Items 
    Dim oFinalItems As Outlook.Items 
    Dim oAppt As Outlook.AppointmentItem 
    Dim strRestriction As String 
    ' Declare a FileSystemObject, and prepare it to take the data. 
    Dim fso, MyFile 
    Set fso = CreateObject("Scripting.FileSystemObject") 
    Set MyFile = fso.CreateTextFile("c:\test\CalendarLogOutput.log", True) 

    daStart = Format(Date, "mm/dd/yyyy hh:mm AMPM") 
    daEnd = DateAdd("d", 30, daStart) 
    daEnd = Format(daEnd, "mm/dd/yyyy hh:mm AMPM") 
    Debug.Print "Start:", daStart 
    Debug.Print "End:", daEnd 

    ' Construct a filter for the next 30-day date range. 
    strRestriction = "[Start] >= '" & daStart _ 
    & "' AND [End] <= '" & daEnd & "'" 
    Debug.Print strRestriction 

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

    ' To include recurring appointments, sort by using the Start property. 
    oItems.IncludeRecurrences = True 
    oItems.Sort "[Start]" 

    ' Restrict the Items collection for the 30-day date range. 
    Set oItemsInDateRange = oItems.Restrict(strRestriction) 

    ' Construct a filter for subjects that contain 」team」. 
    Const PropTag As String = "http://schemas.microsoft.com/mapi/proptag/" 
    strRestriction = "@SQL=" & Chr(34) & PropTag _ 
     & "0x0037001E" & Chr(34) & " like '%team%'" 

    ' Restrict the last set of filtered items for the subject. 
    Set oFinalItems = oItemsInDateRange.Restrict(strRestriction) 

    ' Sort and print the final results. 
    oFinalItems.Sort "[Start]" 
    For Each oAppt In oFinalItems 

     'Here I need to find out how large the body is... 
     If oAppt.Body.Find("BCFLUP") Is Not Nothing Then 
      MyFile.WriteLine (oAppt.Start & "; " & oAppt.Subject & "; " & "Requires FLUP") 
     End If 

     'This line outputs simple data. 
     'Debug.Print oAppt.Start, oAppt.Subject 
     'MyFile.WriteLine (oAppt.Start & ";" & oAppt.Subject) 
    Next 

    ' Close the file. 
    MyFile.Close 

End Sub 

回答

0

拆分oAppt.Body。

InStr找到字符串。元素位置給出線條。如果從零開始數組,則元素位置爲+1。

相關問題