【发布时间】:2010-08-17 06:36:01
【问题描述】:
我正在使用宏生成新表格。对于新一代工作表,从超过 4 个 MS Access DB 中检索数据。每个数据库至少有 200 个字段。我的宏代码包括
1. Cell locking
2. Alignment and formatting
3. One third of the cells in the sheet had a formulas
4. Cell reference with other Workbooks
我的问题是每一代板材至少需要一个小时才能完成打孔过程。但在我看来,这需要的时间太长了。
我已经添加了Application.ScreenUpdating = True 以加快代码速度,但仍然需要同样的时间。如何加快代码速度,如果您有任何想法,请指导我。
`For Ip = 5 To 150
resp = Range("B" & Ip).Value
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DSN=henkel2;DBQ=C:\Hl-RF\RSF-Temp.mdb;DriverId=25;FIL=MS Access;MaxBufferSize=2048;" _
, Destination:=Range("IV4"))
.CommandText = "select Vles from " & Shtname & " where cint(PrductID)='" & resp & "' and cint(DepotID) = '" & cnt1 & "' and Mnth = '" & mnths & "' and Type='" & typs & "'"
.Name = "tab product"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceConnectionFile = _
"C:\Hl-RF\tabct.odc"
.Refresh BackgroundQuery:=False
End With`
Is There Is any way to Reduce the loop iteration time
提前致谢
【问题讨论】:
-
您应该提供一些代码,以便我们可以看到您在宏中所做的事情。您还应该提供有关 MS access 数据库查询的更具体信息 - 您在 Access 中运行了哪些查询 - 您是否尝试过对查询的性能进行基准测试?您怎么知道 VBA 宏是导致性能不佳的原因?
-
您确实应该在问题标题中使用 Excel,因为我必须阅读整个问题才能理解您的问题仅与 Access 相关。
标签: performance ms-access vba excel