How to Use SharePoint HTTPS URLs in Excel VBA File Copy Operations
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.

- 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.
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.
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.
Navigate to your target SharePoint Document Library in a web browser.
Click the 'Sync' button in the top SharePoint toolbar to synchronize the library with your local OneDrive client.
Open Windows File Explorer and locate the newly synced folder, which usually appears under your organization's name in the left navigation pane.
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 Power Automate for File Transfers
Offload the file upload process to Power Automate, which natively handles Microsoft 365 authentication and avoids the complexity of writing API requests in VBA.
Implement an Authenticated HTTP Upload via VBA
Advanced users can bypass FileSystemObject entirely by using MSXML2.XMLHTTP and ADODB.Stream to perform a direct binary upload via the SharePoint API.
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.

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.




