How to Check SharePoint File Save Status with Excel VBA
Question details
The user needs a reliable method in Excel VBA to confirm whether a file has been successfully saved to a SharePoint location.

- 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.
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.
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.
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.
Create variables for your SharePoint HTTPS URL (fileURL) and a local temporary file path (e.g., using Environ("TEMP") & "\MyFile.csv").
Call the URLDownloadToFile function by passing 0, the fileURL variable, the temporary file variable, 0, and 0 as its arguments.
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.
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 a Mapped Network Path (UNC)
If you map your SharePoint library to a network location or format it as a Universal Naming Convention (UNC) path, you can use the standard VBA Dir function.
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. Download WPS Office: Visit the official WPS website and click the free download button for your operating system.
- 2. Install the Software: Run the downloaded installation file and follow the simple on-screen instructions to complete the setup.
- 3. Open Your Spreadsheets: Launch WPS Spreadsheet to open, edit, and run macros on your existing Excel files effortlessly.

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.




