find a text in a file name

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to loop throught n- number of files in a directory and if there is a
string "YTD" in the file name I had to put in cell B3 the string "YTD" and
close it.
Any help with the code will be appreciated
Thanks
Vlad
 
sName = Dir("C:\Someplace\*.xls")
Do while sName <> ""
if instr(sName, "YTD") then
workbooks.Open "C:\Someplace\" & sName
worksheets(1).Range("B3").Value = "YTD"
activeWorkbook.Close SaveChanges:=True
end if
sName = Dir()
Loop
 
Tom,
Thanks for the help.
As usual clean and right to the point.

Thanks again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top