Hello,
This is my first post so if anything is wrong with it I apoligize in advance. I have looked everywhere and come up empty handed trying to make a macro that exports an excel table to SQL server through an odbc connection. As of right now, I currently am able to access the database and import a particular table to my spreadsheet. The code that makes this connection is here:
Now what I want to do is set up something similar to go the other direction, using INSERT statements to populate a database table with the table that had been imported into Excel. Any help in setting up the initial connection or a reference would be great. It seems there is a lot of information out there for other connection types and scenarios, but nothing I could find on this. Thanks a lot.
This is my first post so if anything is wrong with it I apoligize in advance. I have looked everywhere and come up empty handed trying to make a macro that exports an excel table to SQL server through an odbc connection. As of right now, I currently am able to access the database and import a particular table to my spreadsheet. The code that makes this connection is here:
Code:
With Sheet2.ListObjects.Add(SourceType:=0, Source:= _
"ODBC;DSN=" + DSN + ";Trusted_Connection=Yes;APP=2007 Microsoft Office system;DATABASE=" + DATABASE + ";" _
, Destination:=Range("Sheet2!$A$1")).QueryTable
.CommandText = Array( _
"SELECT * FROM " + DATABASE + ".dbo." + TABLE + " " + TABLE _
)
Now what I want to do is set up something similar to go the other direction, using INSERT statements to populate a database table with the table that had been imported into Excel. Any help in setting up the initial connection or a reference would be great. It seems there is a lot of information out there for other connection types and scenarios, but nothing I could find on this. Thanks a lot.