Insert a row to a worksheet by using the SQL statement : Excel ADO « Excel « VBA / Excel / Access / Word






Insert a row to a worksheet by using the SQL statement

 

Public Sub WorksheetInsert()
  Dim Connection As ADODB.Connection
  Dim ConnectionString As String
  ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ThisWorkbook.Path & "\Sales.xls;" & _
    "Extended Properties=Excel 8.0;"
    
  Dim SQL As String
    
  SQL = "INSERT INTO [Sales$] VALUES('VA', 'On', 'Computers', 'Mid', 30)"

  Set Connection = New ADODB.Connection
  Call Connection.Open(ConnectionString)
    
  Call Connection.Execute(SQL, , CommandTypeEnum.adCmdText Or ExecuteOptionEnum.adExecuteNoRecords)
  Connection.Close
  Set Connection = Nothing
End Sub

 








Related examples in the same category

1.Opening an Excel Spreadsheet with ADO
2.Use ADO to read the data from Access database to Excel
3.open the Excel worksheet, create a recordset with the data in the sheet, and then print it in the Immediate window.
4.Excel based database