2016-11-01 4 views
4

단어 문서의 모든 표제의 모든 색상을 한꺼번에 변경하는 매크로를 작성하려고합니다.단어의 모든 표에있는 모든 테두리의 색상을 바꿉니다.

이 내 테이블 만 상단과 하단 경계 변경하고 나의 시도 :

Sub ChangeTableBordersColors() 
Dim mycolor As WdColor 
Dim myTable As Table 
mycolor = wdColorRed 
For Each myTable In ActiveDocument.Tables 
With myTable 
.Borders(wdBorderTop).Color = mycolor 
.Borders(wdBorderBottom).Color = mycolor 
.Borders(wdBorderHorizontal).Color = mycolor 
.Borders(wdBorderVertical).Color = mycolor 
.Borders(wdBorderLeft).Color = mycolor 
.Borders(wdBorderRight).Color = mycolor 
End With 
Next 
End Sub 

사람이이 문제를 해결하는 방법을 제안 할 수 있습니까?

+0

나는이를 복제 할 수 없습니다 - 코드 나를 위해 잘 작동합니다 : (! 약간 추하고 끔찍하게 느린 있지만)

다음 수정했다. – Comintern

답변

1

나는 완전한 기계공을 얻지 못했지만 일부 경계선이 개별적으로 설정되면 코드가 작동하지 않는 것으로 보입니다. LineStyle과 LineWidth를 먼저 재설정 한 다음 색상이 작동합니다.
이이을 단축 할 수 있습니다

With myTable 
     .Borders.InsideLineStyle = wdLineStyleSingle 
     .Borders.InsideLineWidth = wdLineWidth025pt 
     .Borders.InsideColor = mycolor 

     .Borders.OutsideLineStyle = wdLineStyleSingle 
     .Borders.OutsideLineWidth = wdLineWidth025pt 
     .Borders.OutsideColor = mycolor 
    End With 
+0

대단히 고마워요. 문제가되어야합니다. 제가 가지고있는 문서는 개별적으로 설정된 다른 선 스타일을 사용합니다. 개별적으로 설정된 선 스타일을 잃지 않고 매크로를 사용하여 모든 색상을 변경하려고했습니다. 스타일과 색상을 함께 설정해야하는 것 같습니다. – TimF

1

당신에게 너무 많은 KekuSemau 감사 - 당신은 문제가 내가 솔루션을 볼 수 있었던 것을 지적하면. 내 실수는 그것이 개별적으로 국경을 설정했을 때 전체 테이블을 다루려고하는 것이 었습니다. 각 셀을 개별적으로 처리해야했습니다.

Sub ChangeTableBordersColors() 
Dim mycolor As WdColor 
Dim aTable As Table 
Dim i As Integer 
Dim j As Integer 
Dim Row As Integer 
Dim Column As Integer 

mycolor = wdColorRed 
For Each aTable In ActiveDocument.Tables 
i = aTable.Rows.Count 
j = aTable.Columns.Count 
For Row = 1 To i 
For Column = 1 To j 
    With aTable.Cell(Row, Column) 
    .Borders(wdBorderTop).Color = mycolor 
    .Borders(wdBorderBottom).Color = mycolor 
    .Borders(wdBorderLeft).Color = mycolor 
    .Borders(wdBorderRight).Color = mycolor 
    End With 
Next Column 
Next Row 
Next 
End Sub 
관련 문제