Hello
I have a problem when publish report . usually my employee publishes the report in the ending of current month this is not problem, but sometimes can happen in the beginning of next month for the previous month . for instance the report finishis for the AUG month is 08/31/2022 but the employee published the report in 1 or 2 or 3 ... for SEP month so based on my code when show the name file will be . for instance REPORT 09-2022 but the right name should be REPORT 08-2022(this means after on 28 or on 30 or on 31 based on ending of the month ) . so how can I add some conditions if it happened , How can I overcome this problem,please?
Sub copysheet()
Dim ws As Worksheet, StrPath As String
Application.DisplayAlerts = False
'For Each ws In ThisWorkbook.Worksheets
StrPath = ActiveWorkbook.Path & "\"
Set ws = sheet2
ws.Copy
' wb_name = ws.Name
ActiveWorkbook.SaveAs Filename:= _
StrPath & "REPORT " & Format(Date, "MM-yyyy") & ".xlsx", FileFormat:=51
ActiveWorkbook.Close
'Next ws
Application.DisplayAlerts = True
End Sub