【问题标题】:Cell Reference on VBA using ADO and SQL使用 ADO 和 SQL 的 VBA 单元格参考
【发布时间】:2020-11-01 04:12:57
【问题描述】:

下面的代码用于连接到共享点列表并删除“代码列”值匹配“值”的行,我可以将下面代码中的“值”更改为单元格引用,例如 [A1]?怎么样?

视频代码来源:https://www.youtube.com/watch?v=UWrVLdFaapQ&list=PLo0aMPtFIFDrcPiWbqJGb3qt3rkOmjDbN&index=5

Sub allTst_SharePoint()


Dim mySQL As String
Dim cnt As ADODB.Connection
Dim rst As ADODB.Recordset
Dim xuser As String
Dim xactivity As String
Dim xtimesince As Date


Set cnt = New ADODB.Connection
Set rst = New ADODB.Recordset


mySQL = "Delete * FROM [mylist] WHERE [Code] = 'VALUE' ;" 


With cnt
    .ConnectionString = _
    "Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=0;RetrieveIds=Yes;DATABASE=mySPsite;LIST={myguid};"
    .Open
End With

cnt.Execute mySQL, , adCmdText
    
If CBool(rst.State And adStateOpen) = True Then rst.Close
Set rst = Nothing
If CBool(cnt.State And adStateOpen) = True Then cnt.Close
Set cnt = Nothing

End Sub

【问题讨论】:

    标签: sql excel vba ado


    【解决方案1】:

    试试

    Dim myValue As String
    myValue = Range("a1")
    mySQL = "Delete * FROM [mylist] WHERE [Code] = '" & myValue & "' ;"
    

    【讨论】:

    • 完美!你太棒了,谢谢你,周末愉快。
    • @DenisAraujo 如果答案已经解决了您的问题,请单击复选标记考虑accepting it。这向更广泛的社区表明您已经找到了解决方案。没有义务这样做。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多