【发布时间】:2019-11-01 04:20:01
【问题描述】:
如何从工作簿中删除所有不需要的查询?
Sub DeleteQuery()
Dim queries As Variant
queries = Array("q1", "q2", "q3")
For Each qr In ThisWorkbook.queries
'Not sure about the syntax of the following line
If qr not in queries Then
qr.Delete
Next qr
End Sub
如果查询不在列表中,则应将其删除
ActiveWorkbook.Queries("Query1").Delete
不起作用,因为不需要的查询的名称不清楚
【问题讨论】:
-
嗨,谢谢。但它仍然假设不需要的查询名称是已知的
-
那么真正的问题是什么?我认为
If qr not in queries Then的事实不会起作用,因为qr.Delete的语法很好