VBA - Saving a workbook in a SharePoint directory

pinarello

New Member
Joined
Jun 1, 2019
Messages
42
Hello,

I want to save a workbook directly to SharePoint. If I know the URL of the SharePoint directory, I can enter it directly into the directory line of the "Save as" dialog window.

But the question now is how I can specify the desired URL for the "Save As" dialog via VBA. Further I would like to know how I can use VBA to save a workbook, without using the "Save As" dialog, directly in a SharePoint directory.

I already tried it with Application.FileDialog(msoFileDialogSaveAs). It shows me the correct directory in the "Save As" dialog window, but if I then check the contents of the SharePoint directory by pressing the "Save" button, I find that my workbook has not been saved.

I would be happy if someone could answer my questions.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hello, Paul,

thank you very much for the link, which also contains the VBA code at the end.

Unfortunately, my VBA knowledge is not sufficient to adapt the code to run in an Excel workbook.
 
Upvote 0
Hi, pinarello.

Simplifying the solution:
First, make sure you have the "correct" path to your folder in SharePoint.
For example, your sharepoint site appears "https://yoursharepoint.sharepoint.com/your_folder/", but the real path is "\\yoursharepoint.sharepoint.com\your_folder" (maybe it has more text between ".com" and "your_folder".

Well, considering you already have that path, then you can use this:

Activeworkbook.SaveAs "\\yoursharepoint.sharepoint.com\your_folder\your_workbook.xlsm" (with quotes or define this path to a variable and include that variable here)

If you want to save a copy and keep your current file opened, just use the function: ActiveWorkbook.SaveCopyAs.
Using "Save Copy As", you can use the function Dir() to check if the file is saved.
If Dir(fullpath) = "" then your file isn't saved.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top