My goal is to get the week number of current week in my subject in my outgoing mail.
Below gives me this week 1 which I'm trying to code my way around and can't solve.
Dose anyone have a VBA based solution for this issue regardless that can work regardless of whichever office version one might have? I use to have 2016, now have 365. Problem is still here..
I have tried below, 'Format(Now - 1, "ww")' to solve but it dosent give current week - 1 week, my logick behind this was Format(Now - 1, "YYYY-MM-DD") which actually outputs today - one day's date.
Sub SendMail()
Dim olApp As Outlook.Application
Dim olEmail As Outlook.MailItem
Set olApp = New Outlook.Application
Set olEmail = olApp.CreateItem(olMailItem)
With olEmail
.BodyFormat = olFormatHTML
.Display
'.HTMLBody = "<p style=font-size:11pt;font-family:Calibri>Text here, but deleted in this moment..</p>" & .HTMLBody
'.Attachments.Add "C:\temp\Bok1.xlsx"
'.To = ""
.Subject = "v" & Format(Now - 1, "ww") & " - PR11"
'.Send
End With
Set olApp = Nothing
Set olEmail = Nothing
End Sub
CodePudding user response:
Format
has optional parameters:
FirstDayOfWeek
FirstWeekOfYear
Based on the comments, it looks like you're looking for:
Format(Date, "ww",,vbFirstFullWeek)
where vbFirstFullWeek
means:
Start with the first full week of the year.