本文介绍了vba尝试使用字符串的许多变体找到一个目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用vba来尝试找到每隔几天更改名称的文件。该文件存储在本地Intranet系统上。

I am using vba to try and locate a file that changes name ever so slightly each couple of days. This file is stored on a local intranet system.

文件名始终为:

Food Specials Rolling Depot Memo xx - xx.xlsm

其中xx可能代表不同周数字例如

Where xx could represent a different week number e.g.

03 - 21
22 - 52
etc..

所以有一天,文件可能如下所示:

So one day the file may look like:

Food Specials Rolling Depot Memo 03 - 21.xlsm

第二天可能会看喜欢:

Food Specials Rolling Depot Memo 22 - 52.xlsm

有没有什么办法可以创建包含我所有周数的2个字符串(即01 - 52),并在文件路径中随机测试这些字符串,如:

Is there any way i could create 2 strings which contain all my week numbers, (i.e. 01 - 52) and test each of these at random within the file path like so:

     WeekNumber1 = 1,2,3,4,5,6,7,8,9,10 etc.
    WeekNumber2 = 1,2,3,4,5,6,7,8,9,10 etc.



    Set wb = Workbooks.Open(sURL & "Food%20Specials%20Rolling%20Depot%20Memo%20" & WeekNumber1 & "%20-%20" & WeekNumber2 & ".xlsm")

MsgBox wb

On Error GoTo 0

谢谢

推荐答案

这是一个简单的方法,使用喜欢

Here is a simple way using Like:

Sub GetTheName()
    Dim s As String, FileName As String

    s = "C:\TestFolder\*.xlsm"

    FileName = Dir(s)

    Do Until FileName = ""
        If FileName Like "Food Specials Rolling Depot Memo*" Then MsgBox FileName
        FileName = Dir()
    Loop
End Sub

这篇关于vba尝试使用字符串的许多变体找到一个目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 20:14