VBA & Macro Problems

Select a File in the Internet Explorer Upload Dialog with VBA

John WilsonJohn Wilson Nov 22, 2026 868 views

Question details

Select a local file in the Internet Explorer upload dialog from a VBA automation routine.

Select a File in the Internet Explorer Upload Dialog with VBA
Product
Internet Explorer and VBA
Device & OS
not provided
Scenario
A VBA routine opens a web page's file upload dialog and needs to enter a complete file path.
Observed behavior
VBA may pause while the dialog is open, or the file path may be entered into the wrong text box.
Before you start

Confirm that the file exists and note the upload dialog's exact title and the shortcut or control used for its File name field. Test in an interactive desktop session where the dialog can receive keyboard input.

Solution 1Recommended

Use a separate VBScript helper to select the upload file

Run a helper before opening the dialog so it can wait for the window and enter the path while VBA is blocked.

This example uses keyboard automation rather than locating the field by its control name. Window titles, keyboard shortcuts, focus, and security settings can affect whether it works.

Internet Explorer is retired. This approach is intended for a legacy Internet Explorer automation environment; it should not be assumed to work with Microsoft Edge IE mode.

1
Create the helper script

In a text editor, save the following as C:\Scripts\upload-helper.vbs. Replace the dialog title and file path with values from your environment: Set shell = CreateObject("WScript.Shell") found = False For i = 1 To 50 If shell.AppActivate("Choose File to Upload") Then found = True Exit For End If WScript.Sleep 200 Next If Not found Then WScript.Quit 1 WScript.Sleep 500 shell.SendKeys "%n" WScript.Sleep 200 shell.SendKeys "^a" shell.SendKeys "C:\Uploads\report.pdf" shell.SendKeys "{ENTER}"

2
Check the field shortcut

Open the upload dialog manually and verify that Alt+N selects the File name field. If it does not, replace the "%n" SendKeys command with a method appropriate for that dialog, such as a verified keyboard sequence or UI Automation targeting the field.

3
Start the helper before the dialog

In VBA, launch the helper asynchronously with Shell "wscript.exe ""C:\Scripts\upload-helper.vbs""", vbNormalFocus. Immediately afterward, invoke the web page's upload control in your existing browser automation code.

4
Verify the selection

Watch the dialog and confirm that the full path appears in File name and that Enter closes the dialog. Check the web page's selected-file display before submitting the upload.

Use a separate VBScript helper to select the upload file
Keyboard automation limitations: The example path avoids characters that SendKeys treats specially, such as plus signs, parentheses, and braces. Other applications stealing focus or a mismatched dialog title can cause input to go to the wrong window. Use a control-based automation method if reliable field targeting is required.
Free Microsoft Office alternative

Work with Office Files in WPS Office

WPS Office is a free, lightweight Office alternative with a familiar interface and Microsoft Office format compatibility for easier migration. It does not fix Internet Explorer dialogs or replace this VBA automation.

Open and edit Microsoft Word, Excel, and PowerPoint formats, including DOCX, XLSX, and PPTXUse a familiar interface for everyday document, spreadsheet, and presentation workPrepare and save Office files before selecting them for uploadMove existing Office documents into a lightweight workspace
QA img-9

Frequently Asked Questions

Why does VBA stop while the upload dialog is open?

The browser may wait for the modal dialog to close before returning control to the VBA routine. Starting a separate helper with VBA's Shell command before opening the dialog lets the helper run independently.

How can I make sure the path goes into the File name field?

Open the dialog manually and test its File name shortcut, such as Alt+N where supported. For more reliable targeting, use UI Automation to identify and interact with the actual field rather than relying on focus.

What if the helper cannot find the upload dialog?

Check the title used in AppActivate against the visible dialog title. Increase the polling period if the dialog opens slowly, and make sure the script is running in the same interactive desktop session.

Can I use any file path with SendKeys?

SendKeys interprets characters such as plus signs, parentheses, and braces as special input. Escape those characters according to SendKeys rules or use a control-based method to set the field value.