[英]Excel VBA runs very slow if any other application opened
I have a excel report with VBA code. 我有一个VBA代码的Excel报告。 It generally runs within 1 minute if no other application opened.
如果没有其他应用程序打开,则通常在1分钟内运行。 Excel report runs become 2 minutes if outlook opened.
如果打开Outlook,Excel报告运行将变为2分钟。 Excel reports runs become 6 minutes if outlook,chrome and bloomberg terminal application opened.
如果打开Outlook,Chrome和Bloomberg终端应用程序,则Excel报告运行将变为6分钟。
The excel report VBA code has been optimized. Excel报告VBA代码已优化。 But it still running slow when other application opend.
但是当其他应用程序打开时,它仍然运行缓慢。 More application opened can make excel report more slow.
打开更多的应用程序可以使excel报告更慢。
Is there anybody can help me solve this issue? 有没有人可以帮助我解决这个问题? Thanks in advance.
提前致谢。
1) A simple solution could be going into task manager and adding a higher CPU priority to Excel. 1)一个简单的解决方案可以进入任务管理器,并为Excel添加更高的CPU优先级。
2) If your VBA is writing values in a excel sheet that has calculations in it, you might want to look into turning off automatic spreadsheet calculations. 2)如果您的VBA在其中包含计算的Excel工作表中写入值,则您可能需要考虑关闭自动电子表格计算功能。
There might be a lot of factors contributing to this issue: 可能有许多因素导致此问题:
Any actions triggered in these events: 在这些事件中触发的任何操作:
Worksheet_Calculate()
Worksheet_Change()
Worksheet_FollowHyperlink()
Worksheet_SelectionChange()
Workbook_SheetCalculate()
Workbook_SheetChange()
Workbook_SheetFollowHyperlink()
external links, and the external file(s) moved or deleted 外部链接,以及移动或删除了外部文件
database connections (check Data Tab -> Connections) (doubtful) 数据库连接(请检查数据选项卡->连接)(可疑)
Invalid Named Ranges (Formula Tab -> Name Manager; any Refs?) 无效的命名范围(“公式”选项卡->“名称管理器”;是否有引用?)
Data validation rules (Data Tab -> Data Validation -> clear all) 数据验证规则(数据标签->数据验证->清除所有)
Are you opening the file from a network location - this will make it much slower 您是从网络位置打开文件吗?这会使它变慢
Conditional Formatting rules? 条件格式规则? - remove all
- 移除所有
Any hidden objects? 有隐藏的物体吗? (Alt + F10 - delete all)
(Alt + F10-全部删除)
Hidden formatting (what is the last used cell with data?) 隐藏的格式设置(最后一次使用数据的单元格是什么?)
Corrupt file 损坏的文件
If the file is corrupt, and it's feasible, try re-creating it from scratch, and run this function first 如果文件损坏,并且可行,请尝试从头开始重新创建它,然后首先运行此功能
functionality before the macro: 宏之前的功能:
Sub MainSubTryMe()
'UnlockSettingsWorksheet
FastWB '<--- Disables all Application and Worksheet level settings
'YOURCODE HERE
XlResetSettings '<--- Restores all Excel settings to defaults
'LockSettingsWorksheet
End Sub
Public Sub FastWB(Optional ByVal opt As Boolean = True)
With Application
.Calculation = IIf(opt, xlCalculationManual, xlCalculationAutomatic)
.DisplayAlerts = Not opt
.DisplayStatusBar = Not opt
.EnableAnimations = Not opt
.EnableEvents = Not opt
.ScreenUpdating = Not opt
End With
FastWS , opt
End Sub
Public Sub FastWS(Optional ByVal ws As Worksheet, Optional ByVal opt As Boolean = True)
If ws Is Nothing Then
For Each ws In Application.ThisWorkbook.Sheets
OptimiseWS ws, opt
Next
Else
OptimiseWS ws, opt
End If
End Sub
Public Sub OptimiseWS(ByVal ws As Worksheet, ByVal opt As Boolean)
With ws
.DisplayPageBreaks = False
.EnableCalculation = Not opt
.EnableFormatConditionsCalculation = Not opt
.EnablePivotTable = Not opt
End With
End Sub
Public Sub XlResetSettings() 'default Excel settings
With Application
.Calculation = xlCalculationAutomatic
.DisplayAlerts = True
.DisplayStatusBar = True
.EnableAnimations = False
.EnableEvents = True
.ScreenUpdating = True
Dim ws As Worksheet
For Each ws In Application.ThisWorkbook.Sheets
With ws
.DisplayPageBreaks = False
.EnableCalculation = True
.EnableFormatConditionsCalculation = True
.EnablePivotTable = True
End With
Next
End With
End Sub
Maybe this will eliminate some VBA causes 也许这将消除一些VBA原因
You Can also Have a look here : 您也可以在这里看看:
Improving calculation performance 提高计算性能
Performance and limit improvements 性能和极限改进
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.