有什么我可以“释放”,使这个更快?

因此,这段代码将遍历演示文稿中的每个图表,并查看内部值的查找/replace。

我的演示文稿通常有100-300个图表,当代码到达演示文稿中的第300个图表时,需要10-30秒来完成所有操作(当我最初运行程序。)

所以我的问题是:有没有办法让这个更快? 我正在考虑一些“从内存中释放”东西的东西,如果VBA拥有它,那将是解决scheme,但是我找不到任何东西。

我补充说

Set c = Nothing Excel.Application.ScreenUpdating = True Excel.Application.EnableEvents = True Excel.Application.DisplayAlerts = True Application.DisplayAlerts = True 

我认为压制一切正在帮助一点点,但我不能告诉Set c = Nothing

必须有一些东西可以“刷新”或“释放”,使每个循环运行相同,而不是减速。

任何帮助感激!

 Option Explicit Private Sub findAndReplaceChrt() 'Timer start Dim StartTime As Double Dim SecondsElapsed As Double StartTime = Timer ' use & vbLF & for alt + enter Dim pptPres As Object Dim sld As Slide Dim shpe As Shape Dim c As Chart Dim sht As Object Dim fndList As Variant Dim rplcList As Variant Dim listArray As Long Excel.Application.ScreenUpdating = False Excel.Application.EnableEvents = False Excel.Application.DisplayAlerts = False Application.DisplayAlerts = False fndList = Array("a", "b", "c", "d", "e", "f") rplcList = Array("1", "2", "3", "4", "5", "6") 'Make pptPres the ppt active Set pptPres = PowerPoint.ActivePresentation 'Loop through each sld and check for chart title, grab avgScore values and create pptTable to paste into ppt chart For Each sld In pptPres.Slides 'searches through shapes in the slide For Each shpe In sld.Shapes 'Checks if shape is a Charts and has a Chart Title If Not shpe.HasChart Then GoTo nxtShpe Set c = shpe.Chart If Not c.ChartType = xlPie Then ActiveWindow.ViewType = ppViewNormal c.ChartData.Activate 'Loop through each item in Array lists For listArray = LBound(fndList) To UBound(fndList) Worksheets(1).Cells.Replace What:=fndList(listArray), Replacement:=rplcList(listArray), _ LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _ SearchFormat:=False, ReplaceFormat:=False Next listArray c.ChartData.Workbook.Close End If Set c = Nothing nxtShpe: Next shpe Next sld Excel.Application.ScreenUpdating = True Excel.Application.EnableEvents = True Excel.Application.DisplayAlerts = True Application.DisplayAlerts = True 'End Timer SecondsElapsed = Round(Timer - StartTime, 2) MsgBox "This code ran successfully in " & SecondsElapsed & " seconds", vbInformation End Sub