I have a workbook called "BR1 PL Month End Recon Aug 2022"
I have the curreent month end on Sheet "Summary" U1 for eg Sept-2022
I have set up a macro to remove the previous month and year and replace it with the current month and Year on sheet "Summary" U1
Howver when running the macro, I get a run time error "Microsoft Excel cannot access the file...... "
The code below is highlighted
See my code below
It would be appreciated if someone could amend my code
I have the curreent month end on Sheet "Summary" U1 for eg Sept-2022
I have set up a macro to remove the previous month and year and replace it with the current month and Year on sheet "Summary" U1
Howver when running the macro, I get a run time error "Microsoft Excel cannot access the file...... "
The code below is highlighted
Code:
ThisWorkbook.SaveAs Left(strFullNm, Len(strFullNm) - 5), 52
See my code below
Code:
Sub SaveWorkbookAsNewName()
Dim strNameToSave As String
Dim strFullNm As String
Dim lPos As Long
Dim s As String
strNameToSave = ThisWorkbook.Worksheets("summary").Range("U1").Value
strFullNm = ThisWorkbook.FullName
If InStr(1, strFullNm, strNameToSave, vbTextCompare) = 0 Then
lPos = Len(strFullNm) - Len(strNameToSave) - 4
Mid(strFullNm, lPos, Len(strNameToSave)) = strNameToSave
ThisWorkbook.SaveAs Left(strFullNm, Len(strFullNm) - 5), 52
End If
End Sub
It would be appreciated if someone could amend my code