|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
如果说楼上代码理解有难度,那么请看下面的代码(应该好理解了!)- Sub main()
- Dim doc As Document, i As Long, arr()
- Set doc = ActiveDocument
- If Not get_data(doc, arr) Then Exit Sub
- For i = 1 To UBound(arr, 2)
- doc.Range(arr(1, i), arr(2, i)).Font.ColorIndex = wdRed
- Next
- End Sub
- Function get_data(ByRef doc As Document, ByRef arr) As Boolean
- Dim n As Long
- With doc.Content.Find
- .Font.ColorIndex = wdRed
- Do While .Execute
- n = n + 1
- ReDim Preserve arr(1 To 2, 1 To n)
- arr(1, n) = .Parent.Start
- arr(2, n) = .Parent.End
- Loop
- End With
- If n > 0 Then get_data = True Else Exit Function
- doc.Content.Font.ColorIndex = wdBlack
- End Function
复制代码
|
评分
-
1
查看全部评分
-
|