gpt4 book ai didi

excel - vba 尝试使用字符串的许多变体查找目录?

转载 作者:行者123 更新时间:2023-12-04 21:57:42 25 4
gpt4 key购买 nike

我正在使用 vba 尝试找到一个每隔几天就会稍微更改名称的文件。此文件存储在本地 Intranet 系统上。

文件名始终为:

Food Specials Rolling Depot Memo xx - xx.xlsm

其中 xx 可以代表不同的周数,例如
03 - 21
22 - 52
etc..

所以有一天文件可能看起来像:
Food Specials Rolling Depot Memo 03 - 21.xlsm

第二天它可能看起来像:
Food Specials Rolling Depot Memo 22 - 52.xlsm

有什么办法可以创建 2 个包含我所有周数的字符串(即 01 - 52)并在文件路径中随机测试每个字符串,如下所示:
     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

谢谢

最佳答案

这是使用 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

enter image description here

关于excel - vba 尝试使用字符串的许多变体查找目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41208224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com