How can macro open daily generated files?

V

Valdemar

Hi all,
please can anybody help me with xls macro? I receive on daily basis txt
files with name that contains actual date. Typically "Data_20100120.txt". I
want to use macro, open files, modify data and add them to another workbook.
That's no problem, but I don't know, how to daily open files with different
name (date).

I am not sure, how can I modify open sentence.....
Workbooks.OpenText Filename:="C:\Data_20100120.txt"
Many many thanks for your help.

Valdemar
 
J

JLGWhiz

Give this a try:

myDate = Format(Date, "yyyymmdd")
Workbooks.OpenText Filename:="C:\Data_myDate.txt"
 
J

JLGWhiz

Try this corrected version:

myDate = Format(Date, "yyyymmdd")
Workbooks.OpenText Filename:="C:\Data_" & myDate & ".txt"

The variable has to be concatenated into the string.
 
M

Mike H

Hi,

Not tested but should work

Mydate = Format(Now, "yyyymmdd")
MyPath = "C:\Data_"
Workbooks.OpenText Filename:=MyPath & Mydate & ".txt"


--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.
 
V

Valdemar

Hi Mike,

fantastic, it works and I am happy

Thanks a lot,

Valdemar

Mike H píše:
 
M

Mike H

Glad i could help
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.
 

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

Top