word vba 中如何选择某一段中有下划线的部分内容作为range, 改为指定的内容
3个回答
展开全部
Public Sub 查找选择()
Dim N As Long
For N = 1 To ActiveDocument.Paragraphs.Count
ks = 0
js = 0
ActiveDocument.Paragraphs(N).Range.Select
bbbb = Selection.Text
sss = Selection.End - 1
Selection.MoveUp Unit:=wdParagraph
For x = 1 To sss
Selection.Find.ClearFormatting
With Selection.Find
.Text = "*"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
aaaaa = Selection.Text
If Selection.Font.Underline = wdUnderlineSingle Then
If ks = 0 Then
ks = x
End If
Else
If js = 0 And ks <> 0 Then
js = x
End If
End If
Next x
If js <> 0 And ks <> 0 Then
ActiveDocument.Paragraphs(N).Range.Select
Selection.MoveUp Unit:=wdParagraph
Selection.MoveRight Unit:=wdCharacter, Count:=ks - 1
Selection.MoveRight Unit:=wdCharacter, Count:=js - ks, Extend:=wdExtend
Selection.Text = "DDDDDD" '指定内容
Selection.Font.Name = "仿宋_GB2312"
Selection.Font.Bold = wdToggle
Selection.Font.Size = 16
Selection.Font.Underline = 0
end if
Next N
End Sub
Dim N As Long
For N = 1 To ActiveDocument.Paragraphs.Count
ks = 0
js = 0
ActiveDocument.Paragraphs(N).Range.Select
bbbb = Selection.Text
sss = Selection.End - 1
Selection.MoveUp Unit:=wdParagraph
For x = 1 To sss
Selection.Find.ClearFormatting
With Selection.Find
.Text = "*"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
aaaaa = Selection.Text
If Selection.Font.Underline = wdUnderlineSingle Then
If ks = 0 Then
ks = x
End If
Else
If js = 0 And ks <> 0 Then
js = x
End If
End If
Next x
If js <> 0 And ks <> 0 Then
ActiveDocument.Paragraphs(N).Range.Select
Selection.MoveUp Unit:=wdParagraph
Selection.MoveRight Unit:=wdCharacter, Count:=ks - 1
Selection.MoveRight Unit:=wdCharacter, Count:=js - ks, Extend:=wdExtend
Selection.Text = "DDDDDD" '指定内容
Selection.Font.Name = "仿宋_GB2312"
Selection.Font.Bold = wdToggle
Selection.Font.Size = 16
Selection.Font.Underline = 0
end if
Next N
End Sub
展开全部
按照你的意图,示意一下
Sub 删除下划线换成_()
'
Selection.Find.ClearFormatting
With Selection.Find
.Forward = True
.Font.Underline = wdUnderlineSingle
End With
Do While Selection.Find.Execute
Selection.Font.Underline = 0
Selection.Font.Name = "仿宋_GB2312"
Selection.Font.Bold = wdToggle
Selection.Font.Color = wdColorRed
Selection.Font.Size = 16
Selection.MoveRight Unit:=wdCharacter
Loop
End Sub
Sub 删除下划线换成_()
'
Selection.Find.ClearFormatting
With Selection.Find
.Forward = True
.Font.Underline = wdUnderlineSingle
End With
Do While Selection.Find.Execute
Selection.Font.Underline = 0
Selection.Font.Name = "仿宋_GB2312"
Selection.Font.Bold = wdToggle
Selection.Font.Color = wdColorRed
Selection.Font.Size = 16
Selection.MoveRight Unit:=wdCharacter
Loop
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用“天马QY ”的方法测试成功,就是不好理解。求大师能解答
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询