首页 > 解决方案 > 在 360 升级之前通过 SQL 查询更新 Excel 表的宏,现在给出错误

问题描述

我有一个电子表格,除其他外,它从各种输入单元格编写 SQL 查询、运行查询并更新数据。后端的 VBA 运行良好,但现在我已升级到 Office 360​​,我得到:

运行时错误“9”:下标超出范围。

这是VBA:

Sub Paid()

Dim strSQL As String
strSQL = Worksheets("SQL").Range("L6")
With ActiveWorkbook.Connections("Paid").OLEDBConnection 'here is the line that errors out
    .BackgroundQuery = False
    .CommandText = strSQL
End With

ActiveWorkbook.Connections("Paid").Refresh

End Sub

我直接在 SSMS 中仔细检查了 SQL,查询工作正常;虽然我不认为查询是问题,但它是这条线:

With ActiveWorkbook.Connections("Paid").OLEDBConnection

有没有人遇到过这个问题,知道如何让数据成功刷新吗?

标签: sqlexcelvba

解决方案


推荐阅读