VBA & Macro Problems

How to Save an Excel File to a Teams or SharePoint Folder with VBA

Muhammad TalhaMuhammad Talha Nov 2, 2026 869 views

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.

How to Save an Excel File to a Teams or SharePoint Folder Using VBA
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.
Before you start

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.

Solution 1Recommended

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.

1
Locate the target folder

Open your destination folder in Microsoft SharePoint or Teams using your standard web browser.

2
Copy the web address

Click inside the address bar of your browser and copy the entire URL of the folder.

3
Format the URL string

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".

4
Execute the SaveAs method

Implement the ActiveWorkbook.SaveAs command using the formatted URL string as the Filename parameter to save the file.

Use the Direct Web URL in the VBA SaveAs Statement
Authentication Required: This macro will only succeed if the user executing it is currently authenticated and has write access to the specific cloud directory.
WPS Macro Support

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. 1. Download WPS Office: Download and install WPS Office for free from the official website.
  2. 2. Open Your Spreadsheet: Launch WPS Spreadsheet and open your .xlsm or .xlsx file containing the macro data.
  3. 3. Enable Macro Support: Navigate to the Developer tab on the top ribbon and ensure Macro functionality is enabled for your session.
  4. 4. Run Your Code: Click on Macros, select your specific VBA script, and execute your automation tasks seamlessly.
Fully compatible with Microsoft Excel (.xlsm) macro-enabled formatsRobust built-in VBA environment for automating complex tasksLightweight application that runs smoothly on most devicesFree to use with an intuitive, familiar tabbed interface
microsoft office alternative - wps office

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.