我们正在发布正文包含当前周数的电子邮件。我已准备好接收电子邮件的vba代码(参考rondebruin),但我无法在当前的一周填写电子邮件正文。
Private Sub Send_Email()
Dim OutApp As Object
Dim OutMail As Object
On Error GoTo errorhandler
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.to = ""
.CC = "" ''
.BCC = ""
.Subject = "Reports"
.HTMLBody = "Hello All," & "<br>" & "<br>" & "Reports for [week_nm] have been published and saved to the designated locations."
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
答案 0 :(得分:0)
要获取当年的当前周数,请使用:
Application.WorksheetFunction.IsoWeekNum (Now())
在您的代码中,将正文行改为类似..
.HTMLBody = "Hello All," & "<br>" & "<br>" & "Reports for week " & Application.WorksheetFunction.IsoWeekNum(Now()) & " have been published and saved to the designated locations."