我尝试使用ADO更改已关闭的Excel工作簿中的数字。我找到了L42在2015年编写的以下代码。但是程序因错误而停止"没有给出一个或多个所需参数的值"。我无法找到遗漏的地方!
Sub ChangeNum()
Dim con As ADODB.Connection, rec As ADODB.Recordset
Dim sqlstr As String, datasource As String
Set con = New ADODB.Connection: Set rec = New ADODB.Recordset
datasource = "D:\DropBox\TraderShare\TraderNum.xlsx"
Dim sconnect As String
sconnect = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & datasource & ";" & _
"Extended Properties=""Excel 12.0 Xml;HDR=YES"";"
con.Open sconnect
sqlstr = "UPDATE [Sheet1$] SET [Number] = ""16900"" WHERE [ID] = INum"
rec.Open sqlstr, con, adOpenUnspecified, adLockUnspecified 'adLockOptimistic , adOpenStatic, adLockReadOnly
con.Close
Set rec = Nothing: Set con = Nothing
End Sub
感谢任何帮助!
答案 0 :(得分:1)
sqlstr = "UPDATE [Sheet1$] SET [Number] = ""16900"" WHERE [ID] = ""INum"""
重要的是感叹号!我不知道为什么这样需要,如果需要感叹号来连接字符串的不同部分。但是他们看起来不合时宜,最后还有1个太多了!
答案 1 :(得分:0)
此错误的常见原因是缺失或拼写错误。我会专门查看SQL语句并查看最新消息