vba:如果我只知道文件名的一部分,我该如何打开一个文件? [英] vba: how do i open a file if i only know part of the file name?

查看:125
本文介绍了vba:如果我只知道文件名的一部分,我该如何打开一个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我知道这个文件名就是这样的。

  filename * esy 

在给定的目录中只有一个这个文件出现。

解决方案

filename * esy 已经是一个shell ready通配符&如果这样,你可以简单地说:

  const SOME_PATH as string =c:\rootdir\
...
Dim file As String
file = Dir $(SOME_PATH&filename * esy&。*)

如果(Len(file) > 0)然后
MsgBoxfound&文件
如果

只需调用(或循环直到空) file = Dir $()获得下一场比赛。


I need to open a file whose full filename I do not know.

I know the file name is something like.

filename*esy

I know definitely that there's only one occurrence of this file in the given directory.

解决方案

filename*esy is already a "shell ready" wildcard & if thats alway the case you can simply;

const SOME_PATH as string = "c:\rootdir\"
...
Dim file As String
file = Dir$(SOME_PATH & "filename*esy" & ".*")

If (Len(file) > 0) Then
  MsgBox "found " & file
End If

Just call (or loop until empty) file = Dir$() to get the next match.

这篇关于vba:如果我只知道文件名的一部分,我该如何打开一个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆