【发布时间】:2018-05-05 09:14:00
【问题描述】:
我需要帮助来创建两个日期之间的日期数组。我正在尝试使用 Exceptions 对象从 MS Project 日历中导出假期。但是,每个 Calendar.Exception 都不是一个日期。它们可以定义为一个日期范围(例如圣诞节假期)。
Sub ArrayOfDates()
Dim StartDate As Date, EndDate As Date, aDates() As Date
StartDate = #1/1/2018#
EndDate = #1/31/2018#
'create array of dates inclusive of endpoints
If EndDate > StartDate Then
End If
End Sub
感谢所有建议。我采用了消除数组的方法:
Sub ExportCalendarHolidays()
Dim calThisPrjCalendar As Calendar, excPeriod As Exception, OutputFileName As String, sOutputLine As String
Dim Period As Date
Set calThisPrjCalendar = ActiveProject.Calendar
OutputFileName = ActiveProject.Path & "\" & "Holidays_" & Format(Now(), "yyyy-mm-dd_hhmmss") & ".csv"
Open OutputFileName For Output As #1
For Each excPeriod In calThisPrjCalendar.Exceptions
For Period = excPeriod.Start To excPeriod.Finish
sOutputLine = Format(Period, "mm/dd/yyyy")
Print #1, sOutputLine
Next Period
Next
'Cleanup
Close #1
End Sub
【问题讨论】:
-
你想在数组中包含开始和结束吗?