Excel VBA更改Application.GetOpenFilename的默认目录

我GOOGLE了,find了我的部分问题的答案,但不是完整的问题。 我想在Excel VBA中使用Application.GetOpenFilename打开一个文件,我希望它打开在与ThisWorkbook.Path相同的目录中。 我发现事先我可以做

OpenPath = ThisWorkbook.Path ChDrive OpenPath ChDir OpenPath 

但是,运行后,如果我运行任何其他Application.GetOpenFilename它仍然会访问相同的目录(直到也许我closuresExcel ???)。 但是,我希望它恢复到默认目录(不pipe那是什么)。 在我的电脑上,这是Windows XP,它恰好是MyDocuments。 但是,一些使用这个的人可能有XP,有些可能有Windows 7.我无法find任何地方如何弄清楚原来的默认目录是什么,这样我可以存储这个,以便我以后可以重置回默认的。 任何帮助将非常感激。

所以,这可能是解决scheme:

 Dim StartingDir as string StartingDir = CurDir '...your code here ChDir StartingDir 'just before you leave 

如有必要,请与Drive类似。

这可能是你想要的

 dim sStarDir as string sStarDir=curDir ... do all you stuff ' now reset! Application.DefaultFilePath=sStarDir 

菲利普