Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Import Excel(2003) into Access(2003)

Status
Not open for further replies.

bcoates

Programmer
Feb 21, 2006
29
0
0
US
I have a Excel workbook with many worksheets, each worksheet corresponds to a table in database. How do i write a vbscript that would sit on the desktop that imports the worksheets to the tables and overwrites the exisitng data?
 
Code:
' choose table name here depending on workstation or 
' from a text file that contains the workstation name and
' the table name. or you can put them in an array
' connect to the database

db_path = "c:\acces_database_name.mdb"  
Set objConnection = CreateObject("ADODB.Connection")
 
objConnection.Open _
   "Provider = Microsoft.Jet.OLEDB.4.0; " & _
   "Data Source = " & db_path

dim table_name, xcl_file_path, sql_string
table_name = "some_table_name"
xcl_file_path = "c:\xcl_files\your_xcl_file_name.xcl"

sql_string = "SELECT * INTO " & table_name & " FROM [Excel 8.0;HDR=Yes;" & _         
        "Database="& xcl_file_path & "].[Sheet1$]"               
objConnection.Execute sql_string
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top