打开对话框默认指定的networkingpath(不驱动器)

我试图将我的打开对话框默认分配给networking上的特定文件夹。 让我们使用path:

\\test\yes\no\ 

下面的代码不起作用,但也不会出错。 我无法弄清楚我做错了什么。

 Private Declare Function SetCurrentDirectory _ Lib "kernel32" _ Alias "SetCurrentDirectoryA" ( _ ByVal lpPathName As String) _ As Long SetCurrentDirectory "\\test\yes\no\" 

我已经看到人们正在这样做的几种方式,但似乎没有任何工作对我来说。 如果有帮助,我正在使用Excel 2010。

我的目录代码:

 With Application.FileDialog(msoFileDialogFolderPicker) SetCurrentDirectory "\\test\yes\no\" .AllowMultiSelect = False If .Show <> -1 Then MsgBox "No folder selected! Exiting script.": Exit Sub myDir = .SelectedItems(1) End With MsgBox "Please choose the folder." Application.DisplayAlerts = False '********************************************************************************************* 'Check for .xls cutsheets; open one at a time with a loop until all file data has been copied '********************************************************************************************* folderPath = myDir If Right(folderPath, 1) <> "\" Then folderPath = folderPath + "\" fileName = Dir(folderPath & "*.xls") Do While fileName <> "" Application.ScreenUpdating = False Set wbkCS = Workbooks.Open(folderPath & fileName) 

我没有得到它使用Application.FileDialogSetCurrentDirectory 。 但是,使用InitialFileName属性并将其设置为"\\test\yes\no\" (即只指定一个path)确实有效。

 With Application.FileDialog(msoFileDialogFolderPicker) .InitialFileName = "\\test\yes\no\" .AllowMultiSelect = False If .Show <> -1 Then MsgBox "No folder selected! Exiting script.": Exit Sub myDir = .SelectedItems(1) End With 

我可以用下面的方法打开一个对话框:

 Private Declare Function SetCurrentDirectory _ Lib "kernel32" _ Alias "SetCurrentDirectoryA" ( _ ByVal lpPathName As String) _ As Long Sub OpenDialogInNetworkPath() SetCurrentDirectory "\\test\yes\no\" FileToOpen = Application.GetOpenFilename _ (Title:="Please choose a file to import", _ FileFilter:="Excel Files *.xls (*.xls),") Workbooks.Open Filename:=FileToOpen End Sub 

这有帮助吗? 你可以请发布完整的macros?