ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Opening a excel file from a macro (https://www.excelbanter.com/excel-programming/434627-opening-excel-file-macro.html)

Graeme

Opening a excel file from a macro
 
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")

Patrick Molloy[_2_]

Opening a excel file from a macro
 
make sure that your computer's date settigns are not American

"Graeme" wrote:

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")


Dave Peterson

Opening a excel file from a macro
 
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.

Graeme wrote:

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")


--

Dave Peterson


All times are GMT +1. The time now is 12:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com