아래 코드를 400 번 실행하고 있습니다. 60 장의 차트가 있습니다. 실행 시간은 300 초입니다. 이 줄을 제거하면Excel - VBA - 액세스 차트 축 - 속도 문제
minVal = 0.02 * (cht.Chart.Axes(xlValue).MaximumScale - cht.Chart.Axes(xlValue).MinimumScale)
속도가 190 초로 향상됩니다. 이 선은 minVal이 0의 직후에 덮어 쓰여지는 경우에는 아무런 영향을 미치지 않습니다. 차트의 축에 액세스하는 것이 왜 시간이 오래 걸리며 해결 방법인지 이해하려고합니다.
Sub quickAdjustLabels()
Dim cht As Excel.ChartObject
For Each cht In ActiveSheet.ChartObjects
isProdChart = 0
If cht.Chart.SeriesCollection(1).ChartType <> 5 Then 'different from pie
minVal = 0.02 * (cht.Chart.Axes(xlValue).MaximumScale - cht.Chart.Axes(xlValue).MinimumScale)
minVal = 0
For Each myCollection In cht.Chart.SeriesCollection
'if Stack and if not white visible (white visible are the bottom of waterfall charts/white unvisible are the NC stacks) => remove label is too small
If (myCollection.ChartType = xlColumnStacked Or myCollection.ChartType = xlColumnStacked100) And (myCollection.Format.Fill.Visible = msoFalse Or myCollection.Format.Fill.ForeColor.RGB <> 16777215) Then
myCollection.ApplyDataLabels
vals = myCollection.Values
For i = LBound(vals) To UBound(vals)
If Abs(vals(i)) < minVal Then myCollection.Points(i).HasDataLabel = False
Next
End If
If myCollection.Name = Range("Client") Then isProdChart = 1 'Identify productivity charts
Next myCollection
'Remove labels on productivity charts
If isProdChart = 1 Then
For Each myCollection In cht.Chart.SeriesCollection
If myCollection.ChartType = xlColumnStacked Then myCollection.DataLabels.Delete
Next
End If
End If
Next cht
End Sub
왜 400 번 실행합니까? 실제 파일에 대한 액세스 권한이 없어도 문제가 무엇인지 말할 수는 없습니다. 그 코드를 하나의 차트에 대해 1000 번 반복하여 "minVal"라인 만 실행하면 0.015 초가 끝나기 때문에 그 라인만으로는 문제가되지 않습니다. –