Vba Outlook附件搜索和主题、日期/时间、描述提取
下面的代码是一个开始。我正试图修改下面的代码,以便在单个工作站的当前会话中选择该计划的特定日期当天或之后找到约会。然后,我想从约会和描述中提取主题行,并将其显示在消息框中,以便将来进行错误检查。如果可能的话,我想在这个片段中添加一个功能,即计算一天中的约会次数 我无法正确设置对象,也无法找到将I绑定到Outlooks数组中正确项的方法。我之所以说Outlooks数组,是因为在基本代码中我有oItems.Itemi,其中我是日历中指定编号处某个约会的项目 也许除了这个项目之外,使用其他东西会更好? 或者最好在数组中找到与我限制搜索的日期相关的项目位置 下面是Dmitry链接之前的旧代码Vba Outlook附件搜索和主题、日期/时间、描述提取,vba,outlook,outlook-2010,Vba,Outlook,Outlook 2010,下面的代码是一个开始。我正试图修改下面的代码,以便在单个工作站的当前会话中选择该计划的特定日期当天或之后找到约会。然后,我想从约会和描述中提取主题行,并将其显示在消息框中,以便将来进行错误检查。如果可能的话,我想在这个片段中添加一个功能,即计算一天中的约会次数 我无法正确设置对象,也无法找到将I绑定到Outlooks数组中正确项的方法。我之所以说Outlooks数组,是因为在基本代码中我有oItems.Itemi,其中我是日历中指定编号处某个约会的项目 也许除了这个项目之外,使用其他东西会更好?
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
在找到需要的方法和代码后,新代码和新方向。同样,使用新方法,我是否应该将这些数组绑定和数组提取片段分解为单独的子对象
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
我不确定如果oItems>=FormatDate,mmmm-dd-yyyy这一行应该做什么:您正在将一个Items对象与一个字符串进行比较
有关如何检索特定时间范围内的项目的示例,请参见。您的链接使我找到了丢失的代码。我知道我在使用oItems变量时出错了。感谢您指出If语句中的缺陷。If语句出现的原因是为了限制宏在当前日期之前查找约会的位置。希望我不会懒惰,将能够修改张贴的代码,以便其他人可以使用它。谢谢你,德米特里!我开始使用MSDN库中的代码,这让我走上了一条新的道路,并添加了更多的问题。打开Excel工作簿时遇到问题,我想将SubjectArray的索引放在工作簿的单元格中。我启用了Microsoft Excel 14.0对象库。您可能想启动一个新线程,因为它与Excel非常相关。这对我来说是个好消息,因为这意味着我开始看到我应该在什么时候打破这种局面。这需要我制作一些变量对象吗?public,以便将currentAppointment和SubjectArray传递给将其分配给工作簿中单元格的sub?我不打算在Outlook中运行许多其他宏,所以我猜在“常规减速”部分中的早期绑定应该足够了吧?再次感谢您的时间Dmitry。为什么不将这些值作为参数传递呢?同时,当我在这里的时候,我似乎没有正确地分配excel应用程序,因为我无法让该sub打开excel,我还希望将其放入自己的sub中,并使用某种调试/错误处理程序来检查程序是否在任务管理器中打开。