SharePoint Document Issues

How to Check SharePoint File Save Status with Excel VBA

Natalie TaylorNatalie Taylor Oct 14, 2026 869 views

Question details

The user needs a reliable method in Excel VBA to confirm whether a file has been successfully saved to a SharePoint location.

How to Check SharePoint File Save Status with Excel VBA
Product
Microsoft Excel
Device & OS
not provided
Scenario
A macro is used to save files to a SharePoint site, and the script must verify the file's existence at an HTTP/HTTPS URL.
Observed behavior
The standard VBA Dir function does not natively support HTTP or HTTPS URLs, leading to inaccurate results or failures when checking if the file was saved on SharePoint.
Before you start

Ensure you have read and write permissions to the target SharePoint directory, and verify that your device has an active internet connection to reach the HTTPS URL.

Solution 1Recommended

Verify File Save Status Using the URLDownloadToFile API

Since the Dir function does not support HTTPS URLs, using the Windows API to download the file to a temporary location provides a reliable workaround.

This method utilizes the 'urlmon' library to attempt a file download from the SharePoint URL. If the download succeeds, it confirms the file exists and was saved correctly.

1
Declare the Windows API

At the top of your VBA module, declare the API using: Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As LongPtr, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As LongPtr, ByVal lpfnCB As LongPtr) As LongPtr.

2
Define File Paths

Create variables for your SharePoint HTTPS URL (fileURL) and a local temporary file path (e.g., using Environ("TEMP") & "\MyFile.csv").

3
Execute the Download Function

Call the URLDownloadToFile function by passing 0, the fileURL variable, the temporary file variable, 0, and 0 as its arguments.

4
Evaluate the Return Value

Check the result of the function. If the result equals 0, the file was found and downloaded successfully (meaning it was saved). If not 0, the file does not exist.

5
Delete the Temporary File

Use the VBA 'Kill' command to delete the temporary file from your local drive to clean up the environment after the check.

Verify File Save Status Using the URLDownloadToFile API
Permission Requirements: The user running the macro must have read access to the specific SharePoint file and write access to the local Temp directory.
Free Microsoft Office alternative

Enhance Your Productivity with WPS Office

While resolving complex VBA and SharePoint integration issues in Microsoft Office can be time-consuming, WPS Office offers a free, lightweight, and user-friendly alternative. It features high format compatibility, familiar interfaces, and a robust environment for everyday spreadsheet tasks.

  1. 1. Download WPS Office: Visit the official WPS website and click the free download button for your operating system.
  2. 2. Install the Software: Run the downloaded installation file and follow the simple on-screen instructions to complete the setup.
  3. 3. Open Your Spreadsheets: Launch WPS Spreadsheet to open, edit, and run macros on your existing Excel files effortlessly.
Free and lightweight alternative to Microsoft OfficeSeamless compatibility with Microsoft .xls, .xlsx, and .xlsm formatsFamiliar user interface for quick and easy migrationBuilt-in support for VBA macros in advanced versions
microsoft office alternative - wps office

Frequently Asked Questions

Why does the Dir function return an error with SharePoint URLs?

The standard VBA Dir function is designed to work with local drives and network UNC paths. It does not natively resolve or support HTTP or HTTPS web URLs used by SharePoint, which causes it to fail or return inaccurate results.

Can I check the SharePoint file save status without downloading the file?

Yes, you can use an XMLHTTP request in VBA to check the HTTP status code (e.g., looking for a 200 OK status) of the file URL, or map the SharePoint document library as a network drive to use standard VBA file commands.

Does WPS Spreadsheet support VBA macros?

Yes, the advanced versions of WPS Office include support for VBA, allowing you to run and edit macros originally created in Microsoft Excel, maintaining high compatibility with .xlsm files.