Use ASP to Insert a Record Into Excel 2007

I am trying to find out how to insert a record into  a excel 2007 workbook. I have a sheet called Requests that I would just like to add a new row to when I run my script but I can't figure out the proper syntax. I have attached my current code.
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.open"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\\Inetpub\\db\\OfficeSpaceSummary.xlsx; Extended Properties=""Excel 12.0 Xml; HDR=YES; IMEX=1"";"
Set RS=Server.CreateObject("ADODB.recordset")
RS.Open "INSERT INTO [Requests$] (FirstName) VALUES ('1')"
RS.Close
Set RS = Nothing
oConn.Close

Open in new window

AludaanAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Om PrakashConnect With a Mentor Commented:
Please check the example

For more examples pease check the following URL:
http://support.microsoft.com/kb/247412
  'Create a new connection object for Book1.xls
   Dim conn As New ADODB.Connection
   conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _
      "Data Source=C:\Book1.xlsx;Extended Properties=Excel 12.0;"
   conn.Execute "Insert into MyTable (FirstName, LastName)" & _
      " values ('Scott', 'Brown')"
   conn.Execute "Insert into MyTable (FirstName, LastName)" & _
      " values ('Jane', 'Dow')"
   conn.Close

Open in new window

0
 
AludaanAuthor Commented:
Hello O,

Thank you for the answer, but when I try to run that I get the following error:
Microsoft VBScript compilation  error '800a0401'

Expected end of statement

/scripts/Kiran/billstest.asp, line 2

Dim oConn as New ADODB.Connection
----------^

When I looked up the error I just keep hearing that it means I am not running asp.net, but I checked my system and asp.net 1.1.4322 is enabled. I have asp.net v2.0.50727 as well, but it is prohibited right now. I did turn it on to see if it would help, but it did not. Do you know what may be causing this problem?
0
 
Om PrakashCommented:
Please check the updated code:
'Create a new connection object for Book1.xls    
   Set oConn = Server.CreateObject("ADODB.Connection") 
   conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Book1.xlsx;Extended Properties=Excel 12.0;" 
   Set RS=Server.CreateObject("ADODB.recordset") 
   RS.Open "INSERT INTO [Requests$] (FirstName) VALUES ('1')" 
   RS.Close 
   Set RS = Nothing 
   oConn.Close

Open in new window

0
 
Om PrakashCommented:
Modified Code. This should work..
'Create a new connection object for Book1.xls 
Set oConn = Server.CreateObject("ADODB.Connection") 
conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Book1.xlsx;Extended Properties=Excel 12.0;" 
conn.Execute "Insert into MyTable (FirstName, LastName) values ('Scott', 'Brown')" 
conn.Execute "Insert into MyTable (FirstName, LastName) values ('Jane', 'Dow')" 
conn.Close

Open in new window

0
 
AludaanAuthor Commented:
It turns out to be some sort of permission errors but only on one folder in the whole site. Not sure why that is, but it is something we will resolve in the future. Thank you for your help OM.
0
All Courses

From novice to tech pro — start learning today.