Search code examples
excelvba

Application.FileDialog vs GetOpenFilename: What is the difference?


I'm trying to teach myself VBA during the short holiday break. For my first module, I want to create a module that does the following:

  1. Displays dialog box. Prompts user to select CSV files.
  2. Open the CSV files via loop.
  3. Summarize the CSV files based from their data.

Anyway, for number1, I search and found two methods in examples online: Application.FileDialog and GetOpenFilename. Hm, I was wondering, what is the difference between the two (limitation, capabilities, speed, etc.) Is there a significant advantage of one method over another?

Thanks.


Solution

  • Application.FileDialog is an object. GetOpenFilename is a property. If you call GetOpenFilename, Excel owns the dialog object, configures it, displays it, and gives you the return value. If you use Application.FileDialog, you configure it, display it, and get the return value from the object. Outside of that, they're exactly the same - it's just a matter of who owns and controls the underlying FileDialog.