Opening a excel file from a macro

G

Graeme

When using the below code I open a file with a column of dates in a
"d/mm/yyyy" format eg 1/07/2008.

When I open the file manually the dates are fine however for some unknown
reason when the file opens with the macro dates with a "d" less then 10 are
converted to a date and changes the order of the day and month eg 7/01/2008.

"d" greater than 9 are not regognised as a date and are shown as a text entry.

Does anyone know what is going on??

Workbooks.Open FILENAME:= Range("DEFAULT_FOLDER") & Range

("WORKING_DEFAULT_FILENAME")
 
D

Dave Peterson

If the file you're opening is a CSV file, then rename the file to .txt.

Then instead of using workbooks.open, you can use Workbooks.OpenText. And that
gives you the ability to specify each field (date and the correct order).

ps. When some of your data isn't really converted to a real date, that means
that much of your data that was converted to dates didn't get converted
correctly.

Look at what the source data shows and how the data was brought in. It may be a
date. But it's not the date you want.
 

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