View Full Version : File name with some changing numbers
ced0802
01-05-2016, 08:22 AM
Hi everyone,
I have a file named like : 20160105_1010_StockDetails_Raws
20160105 : no problem = Today's date
But I have the 1010 which is a complete random number.
Is there any way to deal with it? does **** exist in VBA?
Thank you very much in advance.
Paul_Hossler
01-05-2016, 09:11 AM
Is there any way to deal with it? does **** exist in VBA?
Yes and Sort Of
Option Explicit
Sub test()
Dim sPath As String, sFind As String, sFound As String, sNotFound As String
sPath = "c:\Users\Daddy\Documents\"
sFind = sPath & Format(Date, "yyyymmdd") & "_****_" & "StockDetails_Raws.txt"
sFound = Dir(sFind)
MsgBox sFound ' pass string to FileOpen
sFind = sPath & Format(Date, "yyyymmdd") & "_****_" & "XStockDetails_Raws.txt"
sNotFound = Dir(sFind) ' empty string
MsgBox sNotFound
End Sub
ced0802
01-05-2016, 10:51 AM
Thank you very much Paul.
I will try that and let you know.
Many thanks !
Only need one *.
Can use 4 "?"
sFind = sPath & Format(Date, "yyyymmdd") & "_*_" & "StockDetails_Raws.txt"
sFind = sPath & Format(Date, "yyyymmdd") & "_????_" & "StockDetails_Raws.txt"
"_*_" will match "_12345_" and "_123_"
"_????_" will not match "_12345_" nor "_123_"
Paul_Hossler
01-05-2016, 01:23 PM
@SamT -- must be too much New Years
@ced0802-- while the **** would still work, SamT's suggestions are more elegant
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.