Word 2016 VBA에서 루프를 사용하여 테이블의 각 셀 음영을 설정하려고합니다. 약 15 * 15 크기의 테이블에서 작동하는 것으로 보입니다. 20 * 20 이상의 테이블과 같은 Word에서는 더 이상 응답하지 않습니다. 단일 단계를 사용하는 경우에도 프로그램 실행이 올바른 것처럼 보입니다. 나는 ca의 테이블을 위해 이것을 시험해 보았다. 50 * 50. ScreenRefresh 및 ScreenUpdating은 영향을 미치지 않는 것 같습니다. 코드 예제에서 각 셀의 음영을 동일한 배경색으로 설정하는 것은 데모 용이며 마지막으로 좀 더 복잡한 설정을 적용하려고합니다.Word VBA 2016, 테이블 : 루프를 사용하여 셀의 음영을 설정할 때 응답 없음
Sub TableCells_SetBackgroundColors()
' Set background color for each cell in Word table
' Application does not respond if table is larger than about 20*20
' debug single step works in any case
'Application.ScreenUpdating = False
Dim i, k, cntCol, cntRow As Integer
cntCol = 15 ' 20 is not ok
cntRow = 15 ' 20 is not ok
If ActiveDocument.Tables.Count <> 0 Then
ActiveDocument.Tables(1).Delete
End If
ActiveDocument.Tables.Add Range:=Selection.Range, _
numRows:=cntRow, _
NumColumns:=cntCol
Dim myTable As Word.Table
Set myTable = Selection.Tables(1)
With myTable.Borders
.InsideLineStyle = wdLineStyleSingle
.OutsideLineStyle = wdLineStyleSingle
End With
For i = 1 To cntRow Step 1
For k = 1 To cntCol Step 1
myTable.Cell(i, k).Shading.BackgroundPatternColor = wdColorRed
'Application.ScreenRefresh
Next k
Next i
'Application.ScreenUpdating = True
End Sub
응용 프로그램이 더 이상 응답하지 않을 때 대기하려고 했습니까? 코드 실행이 오랜 시간이 걸리면 모든 오피스 애플리케이션은 내가 생각하는 한이 행동을 보입니다.하지만 대개는 기다려도 괜찮습니다. –