Outlook VBA-根据日期替换文本

双子大师

我正在尝试创建一个代码,该代码将根据日期替换占位符文本。这些电子邮件必须与每月在特定日期(第7、14、21和28日)生成的报告相关地发送。我已经准备好替换占位符文本的代码,只是无法弄清楚如何确定要使用的日期(例如,请提供#DATE#的报告)

如果该月的当前日期在该月的第7天或之后,但在14号之前,那么我希望将日期更改为当月的第7天。(例如;请提供2016年6月7日的报告)。

如果该月的当前日期在该月的28号当天或之后,但在下个月的7号之前,那么我希望将日期更改为该月的28号。(例如;请提供2016年6月28日的报告),等等。

我一直在尝试使用if语句并将当前日期插入字符串中,但这是行不通的。

Date1 = Format(Date, "dd")

If Date1 >= 7 And Date1 <= 13 Then
Date2 = "7th"
Else

If Date1 >= 14 And Date1 <= 20 Then
Date2 = "14th"
Else

If Date1 >= 21 And Date1 <= 27 Then
Date2 = "21st"
Else
End If

If Date1 >= 28 And Date1 <= 31 Then
Date2 = "28th"
Else

If Date1 >= 1 And Date1 <= 6 Then
Date2 = "28th"
Else

End If
End If
End If
End If

obj.Subject = Replace(obj.Subject, "#DATE#", Date2)
obj.HTMLBody = Replace(obj.HTMLBody, "#DATE#", Date2)

有人可以提供任何帮助吗?

安倍金
Sub test()

Date1 = Format(Date, "dd")
curMonth = Format(Now, "mmmm yyyy")

Select Case Date1
    Case Is >= 28
        Date2 = "28th " & curMonth
    Case Is >= 21
        Date2 = "21st " & curMonth
    Case Is >= 14
        Date2 = "14th " & curMonth
    Case Is >= 7
        Date2 = "7th " & curMonth
    Case Else
        Date2 = "28th " & Format(Now - 7, "mmmm yyyy")
End Select

End Sub

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章