Reputation: 21
I am trying to build a macro that save excel file to sharepoint based on cell value.
I have two cells that:
*the sharepoint path is copied from Teams using copy link.
Below is the VBA that I used. But whenever I run it, it will show this error.
Run-time error '1004': Method 'SaveAs' of object '_Worksheet' failed
Sub filename_cellvalue()
Path1 = Range("A1").Value
myfilename = Range("A2").Value
ActiveWorkbook.SaveAs Filename:=Path1 & myfilename & ".xlsx"
End Sub
Thank you in an advance.
Upvotes: 0
Views: 3979
Reputation: 728
Saving a worksheet to another file location in SharePoint will only work if ALL the following are true:
When all these conditions are met, the following should do the trick:
Public Sub SaveToSharePoint()
targetFile = Range("A1").Value
targetPath = Range("B1").Value
ActiveWorkbook.SaveAs Filename:=targetPath & targetFile & ".xlsm"
End Sub
Upvotes: 3