|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 413191246se 于 2015-7-3 10:23 编辑
*****************
Sub 全文查找_红色宋体小二_前后添加书名号_通用()
Dim i As Paragraph, e As Long, x As String, y As String, z As String, strColor As String, strFont As String, strSize As String
If MsgBox("是否全文查找?(选否单行查找)", vbYesNo + vbExclamation, "查找颜色/字体/字号_前后添加书名号") = vbYes Then e = 2 Else e = 1
'颜色
InputColor:
x = InputBox("自动/红色/粉红/绿色/蓝色/黄色/橙色/褐色/青色/黑色/白色/茶色/金色/鲜绿/淡紫/靛蓝/天蓝/浅蓝/深黄/海绿/深绿/深红/梅红/深青/青绿/深蓝/淡蓝/酸橙色/浅橙色/橄榄色/水绿色/玫瑰红/紫罗兰/", "请输入颜色名称!", "红色")
If x = "" Then GoTo InputColor
If x = "自动" Then
strColor = wdColorAutomatic
ElseIf x = "红色" Then
strColor = wdColorRed
ElseIf x = "粉红" Then
strColor = wdColorPink
ElseIf x = "绿色" Then
strColor = wdColorGreen
ElseIf x = "蓝色" Then
strColor = wdColorBlue
ElseIf x = "黄色" Then
strColor = wdColorYellow
ElseIf x = "橙色" Then
strColor = wdColorOrange
ElseIf x = "褐色" Then
strColor = wdColorBrown
ElseIf x = "青色" Then
strColor = wdColorTeal
ElseIf x = "黑色" Then
strColor = wdColorBlack
ElseIf x = "白色" Then
strColor = wdColorWhite
ElseIf x = "茶色" Then
strColor = wdColorTan
ElseIf x = "金色" Then
strColor = wdColorGold
ElseIf x = "鲜绿" Then
strColor = wdColorBrightGreen
ElseIf x = "淡紫" Then
strColor = wdColorLavender
ElseIf x = "靛蓝" Then
strColor = wdColorIndigo
ElseIf x = "天蓝" Then
strColor = wdColorSkyBlue
ElseIf x = "浅蓝" Then
strColor = wdColorLightBlue
ElseIf x = "深黄" Then
strColor = wdColorDarkYellow
ElseIf x = "海绿" Then
strColor = wdColorSeaGreen
ElseIf x = "深绿" Then
strColor = wdColorDarkGreen
ElseIf x = "深红" Then
strColor = wdColorDarkRed
ElseIf x = "梅红" Then
strColor = wdColorPlum
ElseIf x = "深青" Then
strColor = wdColorDarkTeal
ElseIf x = "青绿" Then
strColor = wdColorTurquoise
ElseIf x = "深蓝" Then
strColor = wdColorDarkBlue
ElseIf x = "淡蓝" Then
strColor = wdColorPaleBlue
ElseIf x = "酸橙色" Then
strColor = wdColorLime
ElseIf x = "浅橙色" Then
strColor = wdColorLightOrange
ElseIf x = "橄榄色" Then
strColor = wdColorOliveGreen
ElseIf x = "水绿色" Then
strColor = wdColorAqua
ElseIf x = "玫瑰红" Then
strColor = wdColorRose
ElseIf x = "紫罗兰" Then
strColor = wdColorViolet
Else
GoTo InputColor
End If
'字体
InputFont:
y = InputBox("宋/仿/楷/黑(或:宋体/仿宋/楷体/黑体)", "请输入字体名称! ", "宋体")
If y = "" Then GoTo InputFont
If y = "宋" Or y = "宋体" Then
strFont = "宋体"
ElseIf y = "仿" Or y = "仿宋" Then
strFont = "仿宋_GB2312"
ElseIf y = "楷" Or y = "楷体" Then
strFont = "楷体_GB2312"
ElseIf y = "黑" Or y = "黑体" Then
strFont = "黑体"
Else
GoTo InputFont
End If
'字号
InputSize:
z = InputBox("一号26/小一24/二号22/小二18/三号16/小三15/四号14/小四12/五号10.5/小五9/六号7.5", "请输入字号大小!(必须输入数字!)", "18")
If z = "" Then GoTo InputSize
If IsNumeric(z) = False Then GoTo InputSize
If z < 1 Or z > 42 Then GoTo InputSize
strSize = z
'执行
If MsgBox("选择结果:" & x & "/" & strFont & "/" & z & "磅!是否继续?", vbYesNo + vbExclamation, "查找颜色/字体/字号") = vbNo Then End
For Each i In ActiveDocument.Paragraphs
i.Range.Select
If e = 1 Then
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine
If Asc(Selection) = 13 Then
i.Range.Select
Selection.HomeKey Unit:=wdLine
Do
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If Selection.Characters.Last.Text = vbCr Then Exit Do
If (Selection.Characters.Last.Font.Color = strColor And Selection.Characters.Last.Font.Name = strFont) And Selection.Characters.Last.Font.Size = strSize Then
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If (Selection.Characters.Last.Font.Color = strColor And Selection.Characters.Last.Font.Name = strFont) And Selection.Characters.Last.Font.Size = strSize Then
Do
If Selection.Characters.Last.Text = vbCr Then Exit Do
If (Selection.Characters.Last.Font.Color = strColor And Selection.Characters.Last.Font.Name = strFont) And Selection.Characters.Last.Font.Size = strSize Then
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Else
Selection.MoveEnd Unit:=wdCharacter, Count:=-1
Exit Do
End If
Loop
Else
Selection.MoveEnd Unit:=wdCharacter, Count:=-1
End If
Selection.InsertBefore Text:="《"
Selection.Font.Color = strColor: Selection.Font.Name = strFont: Selection.Font.Size = strSize
If Selection.Characters.Last.Text = vbCr Then Selection.MoveEnd Unit:=wdCharacter, Count:=-1
Selection.InsertAfter Text:="》"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Else
Selection.MoveRight Unit:=wdCharacter, Count:=1
End If
Loop
End If
ElseIf e = 2 Then
Selection.HomeKey Unit:=wdLine
Do
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If Selection.Characters.Last.Text = vbCr Then Exit Do
If (Selection.Characters.Last.Font.Color = strColor And Selection.Characters.Last.Font.Name = strFont) And Selection.Characters.Last.Font.Size = strSize Then
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If (Selection.Characters.Last.Font.Color = strColor And Selection.Characters.Last.Font.Name = strFont) And Selection.Characters.Last.Font.Size = strSize Then
Do
If Selection.Characters.Last.Text = vbCr Then Exit Do
If (Selection.Characters.Last.Font.Color = strColor And Selection.Characters.Last.Font.Name = strFont) And Selection.Characters.Last.Font.Size = strSize Then
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Else
Selection.MoveEnd Unit:=wdCharacter, Count:=-1
Exit Do
End If
Loop
Else
Selection.MoveEnd Unit:=wdCharacter, Count:=-1
End If
Selection.InsertBefore Text:="《"
Selection.Font.Color = strColor: Selection.Font.Name = strFont: Selection.Font.Size = strSize
If Selection.Characters.Last.Text = vbCr Then Selection.MoveEnd Unit:=wdCharacter, Count:=-1
Selection.InsertAfter Text:="》"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Else
Selection.MoveRight Unit:=wdCharacter, Count:=1
End If
Loop
End If
Next
End Sub |
|