我正在尝试将打开的对话框指定为默认设置为网络上的特定文件夹。让我们使用路径:
\\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)