Last post Nov 15, 2011 08:56 PM by StrangerMike
Nov 15, 2011 08:18 PM|StrangerMike|LINK
I was successful importing an excel file into an access table, where the excel file did not have a header.
Now I am trying to import another excel file with a header, but I keep getting this error:
'wrtn0911$' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.
Here is the code: It's almost identical to the one that works, other than the HDR=Yes
The excel file is called wrtn0911.xls so why does it keep telling me it is not a valid name?!
Dim filename As String
Dim Excel As String
Excel = "C:\bank\wrtn0911.xls"
filename = "wrtn0911"
Dim connect As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Excel & _
";Extended Properties=""Excel 8.0;HDR=Yes;"""
Using conn As New OleDbConnection(connect)
Using cmd As New OleDbCommand()
cmd.Connection = conn
cmd.CommandText = "INSERT INTO [MS Access;Database=" & Access & "].[tblExlWrtn] SELECT * FROM [" & filename & "$]"
Catch ex As Exception
Nov 15, 2011 08:56 PM|StrangerMike|LINK
I found this
At first it did not make sence to me since I am not an Excel expert. I did not know that you could name individual sheets inside of an excel file.
So even though the excel file name was wrtn0911, the sheet inside was named something else. I've seen other posts about similar problems, so
check inside the excel file and make sure you have a sheet named.....(whatever it is you are trying to import)!