Blog/Excel VBA/Application.GetOpenFilename

VBA GetOpenFilename: A File Picker Dialog for Your Macros

vba getopenfilename: Application.GetOpenFilename dialog letting a user pick a bank statement CSV to import

Application.GetOpenFilename shows the standard Windows file picker and hands the chosen path back to your macro as a string — so a bank statement import stops depending on a folder path that inevitably moves.

Prashant Panchal
Prashant Panchal

ACA | FMVA® | 19 Years in Finance

This guide is part of the FinDataPro Excel VBA Workbook Events series.

What Is GetOpenFilename?

Option Explicit

Sub ImportBankStatement()
    Dim filePath As Variant

    filePath = Application.GetOpenFilename( _
        FileFilter:="CSV Files (*.csv), *.csv", _
        Title:="Select the Bank Statement CSV")

    If filePath = False Then
        MsgBox "No file selected. Import cancelled.", vbInformation
        Exit Sub
    End If

    Workbooks.Open Filename:=filePath
End Sub

The dialog opens, the user browses to the bank statement CSV wherever it happens to live this month, and filePath holds the full path — nothing hardcoded.

Download the Example Workbook — Free

The working .xlsm file with this GetOpenFilename picker already wired up — open it, inspect the standard module, and adapt the file filter to your own import.

Enter your email to get instant access — no spam, ever.

It Returns a Path — It Does Not Open Anything

This is the single most common misunderstanding of this method: GetOpenFilename never touches the file system. It shows a dialog and returns whatever path the user selected, as a string. Opening the file is a separate step — Workbooks.Open in the snippet above, or a text-import routine if you are reading a CSV directly rather than opening it as a workbook.

Finance Use Case: No Hardcoded Bank Statement Paths

A hardcoded path like C:\Statements\Jan2026.csv breaks the moment the file moves, the folder structure changes, or the macro runs on a colleague's machine with a different drive letter. Letting the user pick the file removes that entire category of failure — the macro adapts to wherever the file actually is this month, instead of assuming it never moves.

Handling Cancel Correctly

When the user clicks Cancel, GetOpenFilename returns the Boolean False — not an empty string, not Nothing. Declaring the variable as Variant and checking If filePath = False before using it as a path is what stops a Type Mismatch error from surfacing the moment someone changes their mind and cancels.

Restricting the File Filter

The FileFilter argument keeps the dialog showing only relevant files — CSVs for a bank import, rather than every file type in the folder. Multiple filters can be combined with a comma-separated list if the macro needs to accept both .csv and .txt exports from different banks.

Selecting Multiple Files

Set MultiSelect:=True to let the user select several statements at once — useful for batch-importing several bank accounts in one pass. The return value then becomes an array, not a single path, so the calling code needs a loop rather than a single Workbooks.Open call.

Once the file is picked, check Check If Workbook Is Open before opening it to avoid a duplicate-open conflict, or see Workbooks.Add if the picked file instead needs to seed a brand-new working copy rather than being opened directly.

Full reference: Microsoft Learn Application.GetOpenFilename method reference.

Importing the statement is only half the job

FinDataPro AutoBankRec takes the imported statement and reconciles it against your ERP bank book in under 10 seconds — six matching passes, no manual VLOOKUPs.

See AutoBankRec

Frequently Asked Questions

Does GetOpenFilename actually open the file?

No. It only returns the selected path as a string. You still need Workbooks.Open or an import step using that path.

What does it return if the user clicks Cancel?

The Boolean False, not an empty string. Check against False before using the result as a path.

Can I let the user select multiple files?

Yes — set MultiSelect to True. The return value becomes an array, so loop through it instead of treating it as one path.

Does the file filter syntax work the same on Mac?

No, Mac Excel uses different filter syntax. Test any file-picker macro on the target platform before distributing to Mac users.

Conclusion

GetOpenFilename removes the hardcoded path that breaks the moment a file moves. Check for the False cancel case, filter to the relevant file type, and reach for MultiSelect when the workflow needs several files at once. Once the statement is imported, see AutoBankRec for the reconciliation itself.

Prashant Panchal
Prashant Panchal• ACA | FMVA® | 19 Years in Finance

Prashant Panchal is a Chartered Accountant (ACA) and Financial Modelling & Valuation Analyst (FMVA®) with 19 years of experience in finance, FP&A, and financial modelling across the GCC region. He is the founder of FinDataPro.

Discussion

Leave a Comment

0/2000

Comments are moderated and appear once approved.