j844929
Active Member
- Joined
- Aug 18, 2002
- Messages
- 423
Hi,
I've hit a brick wall with this one. I have the code (which works) to export an Excel named range to an Access (mdb) existing database table, which I have pasted below:
What I'm stuck on is changing this to export to a SQL 2005 database table. Can anyone tell me how to export an Excel named range to SQL?
Thanks for your time.
Tim
I've hit a brick wall with this one. I have the code (which works) to export an Excel named range to an Access (mdb) existing database table, which I have pasted below:
Code:
Sub ExportToAccess()
Dim Conn As ADODB.Connection
Dim strSQL As String, stCon As String, stDB As String
Dim strSQL2 As String
'database path - currently same as this workbook
stDB = ThisWorkbook.Path & Database
stCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=ServerToUse; Initial Catalog=DatabaseName; User Id=MyUsername; Password=MyPassword;" & ";"
'SQL code for GL Insert to Access
strSQL = "INSERT INTO TableName SELECT * FROM [Named_Range$] IN '" _
& ThisWorkbook.FullName & "' 'Excel 8.0;'"
'set connection variable
Set cnt = New ADODB.Connection
'open connection to Access db and run the SQL
With Conn
.Open stCon
.CursorLocation = adUseClient
.Execute (strSQL)
End With
'close connection
Conn.Close
'release object from memory
Set Conn = Nothing
End Sub
What I'm stuck on is changing this to export to a SQL 2005 database table. Can anyone tell me how to export an Excel named range to SQL?
Thanks for your time.
Tim