Hello there,
You can dig into these articles which explain the scenario which might cause this exact scenario.
This will occur if both of the following conditions are true:
-The code in question is contained inside an automatically-running subroutine, such as an Auto_Open or Auto_Close subroutine.
-The code is not contained in a Visual Basic module, but "behind" a worksheet or the workbook itself.
VBA code "behind" a worksheet or a workbook may not work in Excel https://support.microsoft.com/en-us/topic/vba-code-behind-a-worksheet-or-a-workbook-may-not-work-in-excel-f2de64d3-a926-7035-e18e-1697f0a32bc5
Error message when you run a Visual Basic for Applications macro in Excel: "Method 'SaveAs' of object '_Worksheet' failed" https://support.microsoft.com/en-us/topic/error-message-when-you-run-a-visual-basic-for-applications-macro-in-excel-method-saveas-of-object-worksheet-failed-376fcbb2-9941-f34d-1aba-ca602903245f
Hope this resolves your Query !!
--If the reply is helpful, please Upvote and Accept it as an answer–