使用通配符打开 Excel 工作簿 [英] Using a wildcard to open an excel workbook
本文介绍了使用通配符打开 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 工作簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文