excel - 使用文件对话框时,如果文件名包含单词,则过滤文件
问题描述
我想在使用文件对话框选择文件时过滤文件。我想排除名称中包含“冲突”的任何文件。这可能吗?
Sub OpenMultipleFiles()
Dim fd As FileDialog
Dim fileChosen As Integer
Dim basename As String
Dim fso As Variant
Set fso = CreateObject("Scripting.FileSystemObject")
Set fd = Application.FileDialog(msoFileDialogFilePicker)
basename = fso.getBaseName(ActiveWorkbook.Name)
fd.InitialFileName = ActiveWorkbook.Path ' Set Default Location to the Active Workbook Path
fd.InitialView = msoFileDialogViewList
fd.AllowMultiSelect = True
fd.Filters.Add "All supported files", "*.xlsm"
fileChosen = fd.Show
If fileChosen = -1 Then
StartAlgo
Dim myArray As Variant
Dim FullPath As String
Dim FileName As String
Dim x As Long
'open each of the files chosen
For x = 1 To fd.SelectedItems.Count
FullPath = fd.SelectedItems(x)
FileName = fso.getFileName(fd.SelectedItems(x))
CopyContractTbls FullPath, FileName
Next x
EndAlgo
Else
MsgBox "Aborted"
Exit Sub
End If
End Sub
解决方案
推荐阅读
- isabelle - Isabelle 不评估引理
- windows - 尝试将powershell脚本编译为带有参数的exe
- sql - 在 oracle 中转换为 DD-MON-YYYY 格式
- django - 我们可以直接在 django rest 序列化器中保存 django 表单数据吗?
- python - 在python中-从概率分布P中找到1000个大小为n的样本的平均中位数
- kubernetes - 用于 GKE 服务和入口的 GCloud API
- dart - Aqueduct 服务器升级到 4.0.0 后退出工作
- sql - 如何从视图中删除列
- scala - 无法破坏scala进程
- python - CX Freeze No mpl_toolkits Module found 错误和 Pyinstaller 无法打开 self .exe 当我将其复制到 C 驱动器以外的其他位置时