VBA & Macro Problems

How to Use SharePoint HTTPS URLs in Excel VBA File Copy Operations

Huma Ashraf ChHuma Ashraf Ch Nov 11, 2026 869 views

Question details

The user needs to copy files directly to a SharePoint HTTPS URL using FileSystemObject.CopyFile in an Excel VBA macro, but the operation fails.

How to Correctly Use SharePoint Paths in Excel VBA File Copy Operations
Product
Excel
Device & OS
not provided
Scenario
Automating file copy operations from a local machine to a SharePoint document library using Excel VBA macros.
Observed behavior
FileSystemObject.CopyFile fails to execute because it only supports local file-system paths and cannot directly copy files to an HTTPS SharePoint URL.
Before you start

Verify your SharePoint folder permissions and ensure you have the OneDrive desktop client installed if you plan to use local folder synchronization as a workaround.

Solution 1Recommended

Use a Locally Synchronized SharePoint Folder

The simplest and most reliable workaround is to synchronize your SharePoint document library to your local machine, allowing FileSystemObject to use standard local file paths.

Since FileSystemObject cannot process HTTPS URLs, mapping the SharePoint library to a local folder bridges the gap. This method requires the OneDrive sync client to be running on the machines of all users who will execute the macro.

1
Open SharePoint Library

Navigate to your target SharePoint Document Library in a web browser.

2
Sync to Local Machine

Click the 'Sync' button in the top SharePoint toolbar to synchronize the library with your local OneDrive client.

3
Locate the Synced Folder

Open Windows File Explorer and locate the newly synced folder, which usually appears under your organization's name in the left navigation pane.

4
Update VBA Code

Modify your VBA FileSystemObject.CopyFile destination path to point to this new local directory (e.g., 'C:\Users\Username\Organization\SharePointFolder\') instead of the HTTPS URL.

Use a Locally Synchronized SharePoint Folder
Synchronization Required: If you are distributing this macro to other users, they must also have the same SharePoint folder synchronized to their local machines.
Free Microsoft Office alternative

Try WPS Office for Seamless Spreadsheet and Macro Management

While integrating legacy VBA macros with modern cloud platforms like SharePoint can be complex, WPS Office provides a lightweight, highly compatible, and free alternative. Enjoy familiar spreadsheet functions, robust macro support, and excellent format compatibility without the heavy subscription costs.

Fully compatible with Microsoft Excel file formats (.xlsx, .xls, .xlsm, .csv).Robust built-in support for VBA and macros to automate your daily workflows.Lightweight design for faster installation and smoother execution on older devices.Free to download and use with a highly familiar, tabbed interface.
microsoft office alternative - wps office

Frequently Asked Questions

Why does FileSystemObject.CopyFile fail with HTTPS paths?

FileSystemObject is a legacy Windows scripting component designed strictly for interacting with the local file system and standard UNC network paths. It lacks the network protocols required to resolve HTTP/HTTPS URLs or handle modern web-based authentication.

Can I use VBA to map a SharePoint URL to a network drive to solve this?

Mapping a SharePoint document library as a network drive does allow FileSystemObject to work because it treats the drive as a local path. However, this relies on WebDAV technology, which is frequently blocked by modern Microsoft 365 security policies or fails due to authentication timeouts.

Is it possible to pass SharePoint credentials directly within FileSystemObject?

No, the FileSystemObject methods do not accept parameters for usernames, passwords, or OAuth tokens. To pass credentials to a web endpoint in VBA, you must build an authenticated HTTP request using MSXML2.XMLHTTP or WinHttp.

What is the best alternative to VBA for automating SharePoint file operations?

For most Microsoft 365 environments, tools like Power Automate, PowerShell, or Office Scripts are strongly recommended. They handle modern cloud authentication natively and integrate with SharePoint much more securely and reliably than VBA.