MrExcel Publishing
Your One Stop for Excel Tips & Solutions

How to set the default path that is used for opening files (in macro VBA)?


Posted by Krumpin on January 18, 2001 4:44 AM

Hi,

I am working on an MS Excel application. I have written a macro instruction that should show the standard OpenFile box for opening files. That’s OK, but I want this box to be “prepared” (set up) to open files in specific directory (different than that set up in standard Excel settings - Tools/Options/General Tab, "Default File Location").
I have tried to use properties Application.DefaultFilePath. But there is no suggestion in VBA Help how to use it. When I write e.g. Application.DefaultFilePath = "C:\directory”, it doesn’t work. It only set up “C:\dir” as a value of a variable (it can be shown by: MsgBox "The current default file path is " & Application.DefaultFilePath).
Do you anybody know what the matter of the problem is?
Thank you.

Krumpin(CZ)

The example of VBA code (but it doesn’t work correctly):
....
Application.DefaultFilePath = "C:\dir"

newTextFile = Application.GetOpenFilename("Text Files, *.txt")
Workbooks.OpenText _
Filename:=newTextFile, ....


Posted by krumphan@ns.ckdkh.cz on January 18, 2001 6:05 AM

Problem Solved! [How to set the default path that is used for opening files (in macro VBA)?]

The solution of the problem has found (invention of my colleague). It’s very easy. The expression is:
ChDir “C:\dir”
That is fully sufficient.

Krumpin(CZ)