![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I want to selectively copy Excel worksheets and columns to a SQL 2000 database using VBA. Specifically, I want to copy data from any worksheet whose name matches a table in the database and copy the data whose column header matches a column name in the table. I ignore worksheet names and column names that don't match. The program I have written to this point generates DTS tasks to copy worksheets to corresponding tables, but it assumes the worksheet has a column that matches every column in the table. However, I have no control over the contents of the customer's spreadsheet and it may contain more or fewer columns than in my table. Is there some way I can get the column names from the spreadsheet so I can programatically build the proper DataPump task? TIA, William Schmidt |
#3
| |||
| |||
|
|
William, Assuming that you want to avoid Excel Automation, you could retrieve the column names from the source worksheets using ADO or ADOX, assuming the source data is in the tabular format that the Excel driver recognizes as a table. You could retrieve an empty recordset using ADO and check its Fields collection for column names. -Doug -- Douglas Laudenschlager Microsoft SQL Server documentation team Redmond, Washington, USA This posting is provided "AS IS" with no warranties, and confers no rights. "Wm" <wschmidt (AT) egginc_SpamBlocker_ (DOT) com> wrote in message news:O2%23pl$kTEHA.3480 (AT) TK2MSFTNGP11 (DOT) phx.gbl... I want to selectively copy Excel worksheets and columns to a SQL 2000 database using VBA. Specifically, I want to copy data from any worksheet whose name matches a table in the database and copy the data whose column header matches a column name in the table. I ignore worksheet names and column names that don't match. The program I have written to this point generates DTS tasks to copy worksheets to corresponding tables, but it assumes the worksheet has a column that matches every column in the table. However, I have no control over the contents of the customer's spreadsheet and it may contain more or fewer columns than in my table. Is there some way I can get the column names from the spreadsheet so I can programatically build the proper DataPump task? TIA, William Schmidt |
#4
| |||
| |||
|
|
You could retrieve an empty recordset using ADO and check its Fields collection for column names. |
![]() |
| Thread Tools | |
| Display Modes | |
| |