VBA & Macro Problems

How to Change the Default Download Folder in Excel VBA

Kushani NimanthikaKushani Nimanthika Oct 22, 2026 868 views

Question details

The user needs to specify a custom destination folder for files downloaded through an Excel VBA script rather than having them automatically save to the default Windows Downloads directory.

How to Change the Default Download Folder in Excel VBA
Product
Excel VBA
Device & OS
not provided
Scenario
Executing an Excel VBA macro to download files from the web using Internet Explorer automation and the SendKeys function.
Observed behavior
The files are forcefully saved to the default Windows Downloads folder, preventing the user from programmatically controlling the exact destination path.
Before you start

Ensure you have access to the VBA Editor (Developer tab enabled) and back up your current macro code before modifying your download procedures.

Solution 1Recommended

Replace SendKeys with an XMLHTTP Request

Using an HTTP request allows you to fetch the file in the background and use an ADODB Stream to save it directly to any specified local folder.

Relying on SendKeys to interact with browser download prompts is highly unreliable. An XMLHTTP request fetches the file data directly, allowing you to build the exact target folder path and file name before committing the save.

1
Open the VBA Editor

Press ALT + F11 in your spreadsheet to open the Visual Basic for Applications window, and navigate to the module containing your download script.

2
Initialize the HTTP Request

Declare an 'MSXML2.XMLHTTP' object. Use the '.Open "GET", URL, False' method followed by '.Send' to request the file directly from the server without invoking a browser interface.

3
Verify Folder Existence

Use the 'Dir' function in VBA to check if your desired target folder exists. If it does not, use the 'MkDir' command to create the directory programmatically.

4
Save the Response Stream

Declare an 'ADODB.Stream' object, set its type to binary (Type = 1), and open it. Write the 'ResponseBody' from your HTTP request into the stream, then use the '.SaveToFile' method with your specific folder path and file name.

Replace SendKeys with an XMLHTTP Request
Improved Reliability: This method entirely bypasses the Windows default download folder and operates silently in the background, eliminating the risk of keystroke misdirection.

Run and Manage VBA Macros Seamlessly in WPS Office

WPS Spreadsheet offers an integrated, powerful Developer environment that fully supports editing, debugging, and executing VBA macros, making it incredibly easy to fix automated download paths.

  1. 1. Install WPS Office: Download and install the free WPS Office suite on your computer.
  2. 2. Open Your Macro File: Launch WPS Spreadsheet and open your existing .xlsm or .xlsb file.
  3. 3. Access the VBA Editor: Navigate to the 'Developer' tab on the ribbon and click 'VBA Editor' to seamlessly update your file download paths.
High compatibility with Microsoft Excel VBA syntax and .xlsm files.Built-in Developer tab featuring a robust Visual Basic editor.Fast, lightweight performance that handles complex macro automations smoothly.Free to download and provides an intuitive, familiar spreadsheet interface.
QA img-9

Frequently Asked Questions

Why is SendKeys considered unreliable for downloading files in VBA?

SendKeys simulates physical keystrokes on the active window. If another program pops up, your computer lags, or the user clicks elsewhere, the keystrokes are sent to the wrong window, causing the download to fail or save incorrectly.

How do I check if my custom download folder exists before saving in VBA?

You can use the built-in VBA `Dir` function. For example, `If Dir("C:\MyFolder", vbDirectory) = "" Then` indicates the folder does not exist. You can then use the `MkDir` command to create it before attempting to save.

Can I use VBA to download a file without opening a web browser at all?

Yes. By using either an XMLHTTP request or the Windows `URLDownloadToFile` API function in your VBA code, you can download files silently in the background without launching Internet Explorer or any other browser.