Opening a file whose name is continuously changing

  • Thread starter Thread starter tc
  • Start date Start date
T

tc

hi. i have a CSV file which i need to import on a regular basis. the
second half of the file name keeps changing eg. abcdXXXXXX where
xxxxxx is basically the date which keeps changing. can a macro be made
to automatically open this file and can this file name be split
inorder to use the date in the workbook for other purposes?
 
hi. i have a CSV file which i need to import on a regular basis. the
second half of the file name keeps changing eg. abcdXXXXXX where
xxxxxx is basically the date which keeps changing. can a macro be made
to automatically open this file and can this file name be split
inorder to use the date in the workbook for other purposes?

Just use a wildcard filespec ...

MyFileName = Dir("C:\Somefolder\abcd??????.ext")
if MyFileName = "" Then
msgbox "No file found" exit sub
else
' Parse filespec ...
sDatePart = Split(MyFileName, "\")
sDatePart = Right(Split(sDatePart(Ubound(sDatePart), ".")(0), 6)
'Open file and use the data ...
end if

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
 
Just use a wildcard filespec ...

MyFileName = Dir("C:\Somefolder\abcd??????.ext")
if MyFileName = "" Then
msgbox "No file found" exit sub
else
' Parse filespec ...
sDatePart = Split(MyFileName, "\")
sDatePart = Right(Split(sDatePart(Ubound(sDatePart), ".")(0), 6)
'Open file and use the data ...
end if

Tom Lavedas
===========http://members.cox.net/tglbatch/wsh/

Thanks Tom for your help
 

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