How to Save an Excel File to a Teams or SharePoint Folder with VBA
Question details
The user needs a reliable method to save an Excel workbook directly to a Microsoft Teams or SharePoint folder using a VBA macro, as local directory paths fail.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Automating the file saving process to cloud collaboration platforms like SharePoint and Teams using an Excel VBA script.
- Observed behavior
- Mapped-drive paths and local directory commands (such as ChDir) do not work reliably with cloud files in Teams and SharePoint, causing the SaveAs macro to fail.
Ensure you are actively signed in to your Microsoft account and have edit permissions for the destination SharePoint or Teams folder before running your VBA macro.
Use the Direct Web URL in the VBA SaveAs Statement
Bypass unreliable mapped-drive paths by formatting the direct SharePoint or Teams folder HTTPS URL within your VBA code.
When working with cloud-based endpoints like Teams or SharePoint, local directory commands like ChDir often fail to locate the path correctly. Excel VBA can easily resolve this by using the direct web address (URL) of the folder as the destination path.
Open your destination folder in Microsoft SharePoint or Teams using your standard web browser.
Click inside the address bar of your browser and copy the entire URL of the folder.
In your VBA editor, set up your SaveAs statement. Paste the copied URL and append a forward slash followed by your desired file name. For example: "https://yourcompany.sharepoint.com/sites/foldera/folderb/filename.xlsx".
Implement the ActiveWorkbook.SaveAs command using the formatted URL string as the Filename parameter to save the file.

Run VBA Macros Smoothly in WPS Office
WPS Office provides robust built-in support for VBA macros, allowing you to execute automated scripts and manage complex spreadsheets seamlessly. Here is how you can use macros in WPS Spreadsheet.
- 1. Download WPS Office: Download and install WPS Office for free from the official website.
- 2. Open Your Spreadsheet: Launch WPS Spreadsheet and open your .xlsm or .xlsx file containing the macro data.
- 3. Enable Macro Support: Navigate to the Developer tab on the top ribbon and ensure Macro functionality is enabled for your session.
- 4. Run Your Code: Click on Macros, select your specific VBA script, and execute your automation tasks seamlessly.

Frequently Asked Questions
Why does my VBA macro fail when using a mapped drive path for SharePoint?
Mapped network drives (used with commands like ChDir) rely on local Windows Explorer configurations that can disconnect, time out, or fail to pass authentication credentials properly. Using a direct HTTPS URL in the SaveAs statement ensures Excel communicates directly with the SharePoint server.
Can I use this exact VBA method to save files to OneDrive?
Yes, the same principle applies. You can copy the HTTPS web URL of your OneDrive folder, append your desired file name, and use it in the VBA SaveAs statement to push the workbook directly to your cloud storage.
How do I handle spaces in the SharePoint URL in VBA?
When copying a URL from the web browser, spaces are typically encoded automatically as '%20'. Excel VBA natively understands this URL encoding in the SaveAs command, so you can paste the URL exactly as it appears in your browser without manually changing the spaces.




