【发布时间】:2017-07-18 13:42:05
【问题描述】:
所以我目前正在尝试编写一个代码来将当前日期与其他两个日期进行比较,以确定信息的有效性。例如,如果日期介于一年的第一季度和第二季度之间,则文档上的信息截至第一季度日期(3 月 31 日)。以下是我目前拥有的内容,出于某种原因,即使当前日期是 7 月,代码仍然显示该信息截至 3 月 31 日有效。有人有什么建议吗?
crntDate = Date
q1End = CDate("Mar 31" & " " & Year(Date))
q2End = CDate("Jun 30" & " " & Year(Date))
q3End = CDate("Sep 30" & " " & Year(Date))
q4End = CDate("Dec 31" & " " & Year(Date))
If q1End <= crntDate <= q2End Then
quart = "Q1" & " " & Year(Date)
ElseIf q2End <= crntDate <= q3End Then
quart = "Q2" & " " & Year(Date)
ElseIf q3End <= crntDate <= q4End Then
quart = "Q3" & " " & Year(Date)
Else
quart = "Q4" & " " & Year(Date)
End If
shName = "Quarterly Reporting for" & " " & firstName & " " & lastName & " " & "(" & quart & ")"
With wdApp.ActiveDocument
.SaveAs2 "https://path/" & shName & ".docx"
.Close
End With
【问题讨论】:
标签: vba excel date excel-2010