Hi All,
I receive spreadsheets from two different sources. I need to import both of them into an Access (2010) table. For the most part, the VBA code works as expected.
But I have one issue I'm at a loss to understand. In both spreadsheets there is a column of values, ostensibly numbers, but represented as text since they all have padding leading zeros to represent a total of six digits. I do not need to import the numbers as text, since the field they will eventually occupy is in a table defined as long number. (The created table is subsequently used to update a main demographics table in the DB.)
In VBA code using the spreadsheets from the first source, I include this line of code:
when the routine completes and I look at the table created, the values are indeed numbers with no leading zeros. Also, immediately after the above line of code I inserted a Debug.Print command to see what the NumberFormat returns. In the Immediate window I get a zero (0).
When I run the identical code on the spreadsheets from the second source, the created table shows the numbers as text with the leading zeros. And the Debug.Print shows six zeros (000000) in the Immediate window. However if I insert this next line of code after the one above, the numbers appear as numbers in the created table.
(PS The numbers I need are in differing columns from the two sources; hence one is column 3, the other column 5)
Once I've made the changes to the spreadsheets, I run this next line of code:
(filepathXLWk was set to the filepath of the spreadsheet.)
Now one more piece of info: When I open each of the spreadsheets themselves in Excel and check the column format, in the first, the one that works as expected, the format is "General". But in the second, the format for the column is the first line of the Chinese(PRC) format. (I don't know why since this info is coming from a US company.)
Any insights greatly welcome,
Vic
I receive spreadsheets from two different sources. I need to import both of them into an Access (2010) table. For the most part, the VBA code works as expected.
But I have one issue I'm at a loss to understand. In both spreadsheets there is a column of values, ostensibly numbers, but represented as text since they all have padding leading zeros to represent a total of six digits. I do not need to import the numbers as text, since the field they will eventually occupy is in a table defined as long number. (The created table is subsequently used to update a main demographics table in the DB.)
In VBA code using the spreadsheets from the first source, I include this line of code:
Code:
impfile.Application.ActiveWorkbook.ActiveSheet.Columns(3).NumberFormat = "0"
When I run the identical code on the spreadsheets from the second source, the created table shows the numbers as text with the leading zeros. And the Debug.Print shows six zeros (000000) in the Immediate window. However if I insert this next line of code after the one above, the numbers appear as numbers in the created table.
Code:
impfile.Application.ActiveWorkbook.ActiveSheet.Columns(5).Value =
impfile.Application.ActiveWorkbook.ActiveSheet.Columns(5).Value
(PS The numbers I need are in differing columns from the two sources; hence one is column 3, the other column 5)
Once I've made the changes to the spreadsheets, I run this next line of code:
Code:
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12Xml, "tblImportData", filepathXLWk, True
Now one more piece of info: When I open each of the spreadsheets themselves in Excel and check the column format, in the first, the one that works as expected, the format is "General". But in the second, the format for the column is the first line of the Chinese(PRC) format. (I don't know why since this info is coming from a US company.)
Any insights greatly welcome,
Vic