How can I add the greeting based on the time of day? I've included a Case statement, just not sure how to append the strGreeting to the template.
Of course I just want to add this greeting at the top of the email.
Code: Select all
Sub CreateFromTemplate() Dim MyWeekNum: MyWeekNum = Format(Date, "ww") Dim strGreeting As String Dim MyItem As Outlook.MailItem Set MyItem = Application.CreateItemFromTemplate("C:\Users\gb\AppData\Roaming\Microsoft\Templates\Newsletter.oft") Select Case Time Case Is < TimeValue("12:00"): strGreeting = "Good morning," Case Is < TimeValue("16:30"): strGreeting = "Good afternoon," Case Else: strGreeting = "Good evening," End Select On Error Resume Next With MyItem .To = "firstname.lastname@example.org" .Subject = "Newsletter - Vol. 21 / No. " & MyWeekNum & " (" & Format(Date, "mmm dd, yyyy") & ")" .Display End With On Error GoTo 0 Set MyItem = Nothing End Sub