本文介绍了使用通配符打开excel工作簿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用通配符打开与我的宏工作簿存储在同一文件夹中的工作簿。该文件夹是一个名为 302113-401yr-r01.xlsm
的文件。这是我的代码:
I want to use a wildcard to open a workbook stored in the same folder as my macro workbook. In the folder is a file named 302113-401yr-r01.xlsm
. Here is my code:
Workbooks.Open filename:=ActiveWorkbook.Path & "\302113*.xlsm"
但是,它告诉我没有这样的文件。任何建议?
However, it tells me that there is no such file. Any advice?
推荐答案
我们无法使用通配符打开文件 - 想象如果可以的话混乱!
We cannot open a file using a wildcard - imagine the chaos if we could!
您需要使用 Dir(ActiveWorkbook.Path&\302113 * .xlsm)
循环浏览这返回。如果只有一个,那么只需使用此功能一次:
You'll need to use Dir(ActiveWorkbook.Path & "\302113*.xlsm")
to loop through the files that this returns. If there will only be one then just use this function once:
Dim sFound As String
sFound = Dir(ActiveWorkbook.Path & "\302113*.xlsm") 'the first one found
If sFound <> "" Then
Workbooks.Open filename:= ActiveWorkbook.Path & "\" & sFound
End If
:网络上的技术
这篇关于使用通配符打开excel工作簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!