【发布时间】:2014-06-24 19:15:28
【问题描述】:
所以...我很确定我只是错过了一些非常简单的东西,但我没有在网上看到任何东西。我有一个文件对话框,我需要在其中选择多个文件。看起来很简单。我可以使用“oFileDlg.MultiSelectEnabled = True”选择多个文件,但是当我接受发布到列表框中的所选文件时,只显示一个。我相信它正在做的是将文件名连接成一长行,但我不确定如何将它们分开。任何提示或帮助将不胜感激!!!
代码:
Private Sub cmdSourceAdd_Click()
Dim oFileDlg As FileDialog
' Create a new FileDialog object.
Call ThisApplication.CreateFileDialog(oFileDlg)
' Define the filter to select part and assembly files or any file.
oFileDlg.Filter = "Inventor Files (*.iam;*.ipt;*.idw;*.dwg)|*.iam;*.ipt;*.idw;*.dwg|All Files (*.*)|*.*"
' Define the part and assembly files filter to be the default filter.
oFileDlg.FilterIndex = 1
oFileDlg.MultiSelectEnabled = True
' Set the title for the dialog.
oFileDlg.DialogTitle = "Open File Test"
' Set the initial directory that will be displayed in the dialog.
'oFileDlg.InitialDirectory = ThisApplication.FileOptions.ProjectsPath
' Set the flag so an error will be raised if the user clicks the Cancel button.
oFileDlg.CancelError = True
' Show the open dialog. The same procedure is also used for the Save dialog.
' The commented code can be used for the Save dialog.
On Error Resume Next
oFileDlg.ShowOpen
' oFileDlg.ShowSave
' If an error was raised, the user clicked cancel, otherwise display the filename.
If Err Then
MsgBox "User cancelled out of dialog"
ElseIf Not oFileDlg.fileName = "" Then
lstSource.AddItem oFileDlg.fileName
End If
End Sub
【问题讨论】:
-
当使用
multiselect你会得到一个文件名数组——你需要遍历那个数组。这是给 AutoDesk 的吗? - 如果是这样,您可能应该添加该标签。 -
我做到了 :) 谢谢!我现在正在努力。我不小心创建了一个无限循环:哦哈哈哈这会很有趣
-
我试过了:
Do Until oFileDlg.fileName = "" Loop但它是无止境的,因为它实际上并没有进入下一个文件。我怎样才能让它选择下一个文件? -
我对 AutoDesk 不熟悉,而且它的工作方式似乎与 Office VBA 完全不同,所以我能提供的东西不多。从一点谷歌搜索来看,当您使用多选时,
fileName会以字符串形式返回,其中包含与|连接的文件名,因此您可以尝试使用Split(fileName,"|")创建一个可以循环的数组。 -
就是这样!我无法弄清楚如何设置它。 Jaytek Development 的 Rodney Thomas 帮助了我。答案贴在下面:)
标签: vba openfiledialog autodesk