我使用ADODB查询了一个excel并且有一组数据应该被复制到第二个工作表,但是当我尝试插入数据时,它总是位于第二行而忽略第一行。我认为这是因为第一行始终被视为标题。有没有办法通过创建第一行作为标题并随后使用值(相对于我在下面写的代码)将数据插入到Excel中。
Exceldb = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\VAS_AUTOMATION_v1.1\Book1.xlsx;Extended Properties=""Excel 12.0;HDR=Yes;"";"
Dim sDBConnectionString, i, iCol
Set con = CreateObject("ADODB.Connection")
sDBConnectionString = Exceldb
con.ConnectionString = sDBConnectionString
con.Open
If Err.Number <> 0 Then
For i = 1 to 4
Err.Clear
wait 5
con.Open
If Err.Number = 0 Then
msgbox "opened"
End If
Next
else
msgbox "opened"
End If
strROW = "UNIXOPERATIONS_16"
strROWID = "'" & strROW & "'"
strQuery = "INSERT INTO [Sheet3$A1:A1] (" & strROWID1 & ") Values(" & strROWID & ")"
Set strRecordSet = CreateObject("ADODB.Recordset")
Dim objCmd 'As New ADODB.Command
Set objCmd = CreateObject("ADODB.Command")
Set objCmd.ActiveConnection = con
objCmd.CommandType = 1
objCmd.CommandText = strQuery
Set strRecordSet = objCmd.Execute
con.Close