VBA打开带有通配符的文件,只知道扩展名 [英] VBA Open file with wildcard knowing only extension
本文介绍了VBA打开带有通配符的文件,只知道扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试让Excel打开文件夹
(ThisWorkbook.Path\Peach\Apple)
中的任何文件,具有.xlsm扩展名(总是只有1个文件)。是否可以用通配符打开它?我不知道文件的名称,只是扩展名。
I am trying to get Excel to open any file in the a given folder
(ThisWorkbook.Path\Peach\Apple)
that has .xlsm extension (there is always only 1 file). Is it possible to open it with wildcard character? I do not know the name of the file, just the extension.
如果没有,是否有办法?
If not, is there a way to do it?
推荐答案
只需向文件系统询问第一个匹配的文件:
Just ask the file system for the first matching file:
Dim path As String: path = ThisWorkbook.path & "\Peach\Apple\"
FindFirstFile = Dir$(path & "*.xlsm")
If (FindFirstFile <> "") Then
Workbooks.Open path & FindFirstFile
Else
'// not found
End If
(这不会搜索子目录)
(This will not search sub-directories)
这篇关于VBA打开带有通配符的文件,只知道扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文