Hi everybody, I went through every solution I've found online already and also asked AI for help but nothing.
I keep getting Run-time error '1004': Method 'SaveAs' of object '_Workbook' failed in my code.
This is the code:
Sub Button_ExtractCostPerformance()
Dim Client, Country, Year, Localpath As String
Dim localWB, Cloudfile As Workbook
ActiveWorkbook.Save
Client = ThisWorkbook.Sheets("Output").Range("E9").Value
Country = ThisWorkbook.Sheets("Output").Range("E8").Value
Year = ThisWorkbook.Sheets("Output").Range("E10").Value
Localpath = ActiveWorkbook.FullName
Filename = Client & " - " & Country & " - " & Year
Folder = "URL to SHAREPOINT"
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
Folder & Filename & ".xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Application.DisplayAlerts = True
Workbooks.Open Filename:=Localpath
Workbooks(Filename & ".xlsx").Close
End Sub
One thing to point out is that this code works in 3 out of 4 instances in other files, but in some, I keep getting this error.
Any clues what could be the reason? One thing the AI pointed out is the I can't use SaveAs to save to URL/sharepoint, but as I said it works in other files.
Bookmarks