VBA给选择区域的每段的第一句显示红色的方法
1、打开文档,同时按下fn和F11键打开VBA编辑窗口。

2、鼠标左键双击左侧的“thisdocument”后弹出右侧的vba编乩态祗嚆辑窗口,输入代码“Sub test() On Error Resume Next Dim i As Integer, paph As Paragraph, str As String If Selection.Type = wdSelectionIP Then MsgBox "没有选择": Exit Sub For Each paph In Selection.Paragraphs str = paph.Range.Text i = VBA.InStr(1, str, "。") If i Then ActiveDocument.Range(paph.Range.Start, paph.Range.Start + i).Font.ColorIndex = wdRed End If NextEnd Sub”。

4、页面自动转换到word编辑界面并弹出警示框提醒没有在word中选择要进行修改的内容,点击下方的“确定”。

6、再次回到vba编辑界面,再次点击三角形的运行键后点击左侧的word图标。
