gpt4 book ai didi

excel - 打开对话框默认为指定的网络路径(不是驱动器)

转载 作者:行者123 更新时间:2023-12-02 14:13:35 25 4
gpt4 key购买 nike

我正在尝试将打开的对话框分配为默认网络上的特定文件夹。让我们使用路径:

\\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\" (即仅指定路径)确实有效。

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

关于excel - 打开对话框默认为指定的网络路径(不是驱动器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14203801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com