M
muyBN
I receive a CSV file from a company which I insert into a database. The CSV
has 45 columns/fields in the first row. I would like to know, please, if
anyone can suggest a method which would work better or faster than the one
I'm outlining (in pseudocode) below.
--insert each column/field heading name into an array (strHeading(0), to (44))
--insert data contained in each cell by column into an array
--insert data by row into the database with my array
I will have no problem with the arrays, but as a support to that activity, I
would really like to automate the process of "DIMming" the 45 column heads
according to their respective cell contents so I don't have to do 45 options
in a Select Case statement or something like that.
In other words: (1) I open the CSV file in Word and convert it to a table.
(2) I go from cell to cell in the first row to retrieve the column names.
The column names in the first three cells are Lead_ID, Date, and DataSource.
What I would like to do is DIM a variable per each of these names, for
example, strLead_ID, dtmDate, and strDataSource. I tried the following
without success:
Dim "str" & Selection as String 'throws an error so there's obviously a
concept missing here
Am I on the right track here or do I have to DIM all 45 variables manually?
Also, is there a way to use "range," for example, instead of "Selection" to
determine the contents of a cell? As it is, I go from cell to cell and set
one of the variables equal to the selection. If there is a way of using the
Range attribute, I feel it would tremendously speed up my process as compared
to my present method of using a While to get the content of each cell in a
row by using Selection, then going to the next row until the
Selection.Information(wdWithInTable) = False. It seems like I would do better
to use a Range statement that gets content per
Table(1).Row(intRow).Cell(intCell), but I'm not sure what the exact
statement syntax would be.
Thanks in advance for any help on these two or three task objectives that I
would like to achieve.
has 45 columns/fields in the first row. I would like to know, please, if
anyone can suggest a method which would work better or faster than the one
I'm outlining (in pseudocode) below.
--insert each column/field heading name into an array (strHeading(0), to (44))
--insert data contained in each cell by column into an array
--insert data by row into the database with my array
I will have no problem with the arrays, but as a support to that activity, I
would really like to automate the process of "DIMming" the 45 column heads
according to their respective cell contents so I don't have to do 45 options
in a Select Case statement or something like that.
In other words: (1) I open the CSV file in Word and convert it to a table.
(2) I go from cell to cell in the first row to retrieve the column names.
The column names in the first three cells are Lead_ID, Date, and DataSource.
What I would like to do is DIM a variable per each of these names, for
example, strLead_ID, dtmDate, and strDataSource. I tried the following
without success:
Dim "str" & Selection as String 'throws an error so there's obviously a
concept missing here
Am I on the right track here or do I have to DIM all 45 variables manually?
Also, is there a way to use "range," for example, instead of "Selection" to
determine the contents of a cell? As it is, I go from cell to cell and set
one of the variables equal to the selection. If there is a way of using the
Range attribute, I feel it would tremendously speed up my process as compared
to my present method of using a While to get the content of each cell in a
row by using Selection, then going to the next row until the
Selection.Information(wdWithInTable) = False. It seems like I would do better
to use a Range statement that gets content per
Table(1).Row(intRow).Cell(intCell), but I'm not sure what the exact
statement syntax would be.
Thanks in advance for any help on these two or three task objectives that I
would like to achieve.