Excel VBA: Getting Default File Path

This Excel VBA macro shows a message box with the default path.

Macro Example

Sub GetDefaultFilePath()

 MsgBox Application.DefaultFilePath

End Sub

Description

Application

  Application...

The Application property returns the Application object.

obj-Excel-Global-Application

Application.DefaultFilePath

  Application.DefaultFilePath

The Application.DefaultFilePath property returns or sets the default path.

obj-Excel-Application-DefaultFilePath

The code: Application.DefaultFilePath is set to the parameter of a MsgBox function.
So, a message box displays the default path.

Sub GetDefaultFilePath()

 MsgBox Application.DefaultFilePath

End Sub

Properties

http://www.relief.jp/itnote/archives/017703.php

Apply to

  • Excel 2013
  • Excel 2010
  • Excel 2007