VBS:在Outlook中设置不在办公室答复与开始date和结束date

我正在通过阅读MS Excel工作表的脚本来自动化Outlook中的OOO。

  • 该脚本从input电子表格中读取开始date和结束date,然后在Outlook中为这些date设置不在办公室的回复。
  • 此脚本获取当前date,如果从电子表格中读取的开始date是明天的date,则会提示用户。
  • 这个想法是提醒用户设置OOO,然后根据用户的确认自动设置。 例如,如果excel表格的开始date和结束date分别21-Oct-2016 24-Oct-2016并且如果此脚本在20-Oct-2016运行,则应该能够设置OOO启动21-Oct-201621-Oct-201621-Oct-2016 24-Oct-2016自动(无需打开MS Outlook)
  • 到目前为止,我可以阅读电子表格并获取date。 但是,我不能在以后的时间里设定OOO。

以下是正在进行的代码:

 Sub ReadDataAndSetOOO() Dim objExcel,ObjWorkbook,objsheet intRow = 2 Dim startDateValue, endDateValue Set objExcel = CreateObject("Excel.Application") Set objWorkbook = objExcel.Workbooks.Open("C:\input.xlsx") set objsheet = objExcel.ActiveWorkbook.Worksheets(1) DateToday = FormatDateTime(Date, 1) DateTomorrow = formatDate(FormatDateTime(DateAdd("d", 1, DateToday), 1)) Wscript.Echo DateTomorrow Do Until objExcel.Cells(intRow,1).Value = "" startDateValue = formatDate(FormatDateTime(objsheet.Cells(intRow,1).value,1)) endDateValue = formatDate(FormatDateTime(objsheet.Cells(intRow,2).value)) Wscript.Echo "Start date=" & startDateValue Wscript.Echo "End date=" & endDateValue If DateTomorrow = startDateValue Then 'Following line to be replaced by the code to set OOO between start and end date Wscript.Echo "I am on leave from " & startDateValue & " to " & endDateValue End If intRow = intRow + 1 Loop objExcel.ActiveWorkbook.Close objExcel.Workbooks.Close objExcel.Application.Quit End Sub Function formatDate(myDate) d = parse(Day(myDate)) m = parse(Month(myDate)) y = Year(myDate) formatDate= d & "-" & m & "-" & y End Function Function parse(num) If(Len(num)=1) Then parse="0"&num Else parse=num End If End Function ReadDataAndSetOOO 

我提到了这个链接和其他一些链接,但是在任何地方,OOO立即被设置,而不是所需的开始和结束date。

任何指针赞赏。

OOF时间范围只能通过EWS来设置,即使用UserOofSettings动词。 它不能使用Outlook对象模型或扩展MAPI设置。

如果使用Redemption是一个选项,它将暴露RDOOutOfOfficeAssistant对象。 由于它执行EWS呼叫,它将需要邮箱用户的凭据。

  set Session = CreateObject("Redemption.RDOSession") Session.MAPIOBJECT = Application.Session.MAPIOBJECT Session.Credentials.Add "*.myserver.com", "Domain\UserName", "MyPassword" set OofAssistant = Session.Stores.DefaultStore.OutOfOfficeAssistant OofAssistant.BeginUpdate OofAssistant.StartTime = #12/21/2011# OofAssistant.EndTime = #01/03/2012 9:00# OofAssistant.State = 2 'rdoOofScheduled OofAssistant.ExternalAudience = 1 'rdoOofAudienceKnown OofAssistant.OutOfOfficeTextInternal = "<html><body>I am on vacation from 12/21/2001 until 01/03/2012. Please contact " & _ "<a href=""mailto:Joe.User@MyCompany.com"">Joe User</a>" & _ " if you have any questions</body></html>" OofAssistant.OutOfOfficeTextExternal = "<html><body>I am on <b>vacation</b> until next year. </body></html>" OofAssistant.EndUpdate