我正在尝试使用 VBA 查询 Microsoft Excel 中的表。我已经编写了一些代码来尝试完成此任务,但我不断收到错误:
运行时错误“1004”:说这是一般 ODBC 错误。
我不确定需要做什么才能使该代码正常运行,以便我可以查询该表。
我正在使用 SQL Server Express,我正在连接的服务器:.\SQLEXPRESS
数据库:
查询产品表VBA代码:
Sub ParameterQueryExample()
'---creates a ListObject-QueryTable on Sheet1 that uses the value in
' Cell Z1 as the ProductID Parameter for an SQL Query
' Once created, the query will refresh upon changes to Z1.
Dim sSQL As String
Dim qt As QueryTable
Dim rDest As Range
'--build connection string-must use ODBC to allow parameters
Const sConnect = "ODBC;" & _
"Driver={SQL Server …Run Code Online (Sandbox Code Playgroud) 我在VBA中有一个程序可以过滤表中的值.我正在尝试使这个通用程序适用于您提供的所有表.在我的程序中,我必须设置它正在过滤的表的范围:设置rng = dataSheet.Range("A1:F78").我想知道是否有办法在excel中获取具有某种文本值的表的范围,所以我不必在每个宏中指定它.我想这是一种动态范围.