再来一段五彩纷呈的文字实现代码:
Sub colorChar() Dim myR As Range, i As Byte, iMax As Byte Dim colorArray As Variant Application.ScreenUpdating = False ActiveDocument.Content.Text = "=rand(2,45)" '自动产生虚拟文本 Application.Activate SendKeys "{end}{enter}", True colorArray = Array(wdColorDarkRed, wdColorRed, wdColorDarkGreen, wdColorOliveGreen, _ wdColorBrown, wdColorOrange, wdColorGreen, wdColorDarkYellow, _ wdColorLightOrange, wdColorLime, wdColorGold, wdColorBrightGreen, _ wdColorYellow, wdColorDarkTeal, wdColorPlum, wdColorSeaGreen, _ wdColorDarkBlue, wdColorViolet, wdColorTeal, wdColorIndigo, _ wdColorBlueGray, wdColorTan, wdColorLightYellow, wdColorRose, _ wdColorAqua, wdColorLightGreen, wdColorBlue, wdColorPink, _ wdColorLightBlue, wdColorLavender, wdColorSkyBlue, wdColorPaleBlue, _ wdColorTurquoise, wdColorLightTurquoise) i = 0 iMax = UBound(colorArray) For Each myR In ActiveDocument.Characters myR.Select Selection.Font.Color = colorArray(i) i = IIf(i < iMax, i + 1, 0) '这里使用了IIf函数 Next Application.ScreenUpdating = True Application.Activate End Sub |