Eyan
Eyan

Reputation: 33

Is there a way to use VBA code to save an Excel workbook to Sharepoint?

I get an error on the 'Save on Sharepoint' section. any feedback on my code to save this file to my sharedrive and to a Sharepoint site daily with today's date at the end.

 Sub sharepointsave()

'Open Excel
    Set xl = CreateObject("Excel.Application")
    xl.Workbooks.Open ("S:\Common\test.xlsx")
    xl.Visible = True
    Application.DisplayAlerts = False

'Copy and Save As
    xl.ActiveWorkbook.SaveAs Filename:=("S:\Common\test_" & Format(Now(), "YYYYMMDD") & ".xlsx"), FileFormat:=xlOpenXMLWorkbook

'Save on Sharepoint
    xl.ActiveWorkbook.SaveAs Filename:=("//aticsi.sharepoint.com/sites/test_" & Format(Now(), "YYYYMMDD") & ".xlsx"), FileFormat:=xlOpenXMLWorkbook

'Close without saving over xlsm
    xl.ActiveWorkbook.Saved = True
    xl.Quit
    Set xl = Nothing

End Sub

Upvotes: 1

Views: 5984

Answers (1)

Tim Williams
Tim Williams

Reputation: 166585

This works for me:

ActiveWorkbook.SaveAs "https://mycompany.sharepoint.com/sites/MySite/TestLibrary/Test.xlsx"

Upvotes: 2

Related Questions