|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 weiyingde 于 2017-4-8 07:42 编辑
这是个有关改变字体颜色而达到隐现答案的目的的程序,有两个问题需要优化:
1、切换按钮运行后,删除不见了,如何才能始终保留?
2、运行程序后,行距变大了,由原来的2页变成4页,怎样保持原来版式不变,仍旧是2页。
代码如下:
Private Sub CommandButton1_Click()
With Me.CommandButton1
If .Caption = "隐藏答案" Then
Call 隐显答案
.Caption = "公布答案"
Exit Sub
End If
If .Caption = "公布答案" Then
Call 隐显答案
.Caption = "隐藏答案"
Exit Sub
End If
End With
End Sub
Sub 隐显答案()
With ActiveDocument.Content
With .Find
.Replacement.Font.ColorIndex = 2
.Replacement.Font.Name = "方正姚体"
.Execute "[!^13]@", , , 1, , , , , 1, , 2 '匹配拼音
End With
With .Find
.Replacement.Font.ColorIndex = 1
.Replacement.Font.Name = "华文楷体"
.Execute "[一-﨩]@", , , 1, , , , , 1, , 2
End With
End With
With ActiveDocument.Content.Find
.Execute "[ ]{1,}", , , 1, , , , , , "^32", 2
.Execute "^32{1,}([!^13]@)", , , 1, , , , , , "\1", 2 '"[ā-ê]"
.Execute "^32{1,}([一-﨩]@)", , , 1, , , , , , "\1", 2
.Execute "([\((])^32{1,}", , , 1, , , , , , "\1", 2
.Execute "^32{1,}([\))])", , , 1, , , , , , "\1", 2
.Execute "^32{1,}", , , 1, , , , , , "^32", 2
.Execute "([一-﨩]@)^32{1,}([一-﨩]@)", , , 1, , , , , 2, "\1\2", 2
End With
With ActiveDocument.Content.Find
.Replacement.Font.ColorIndex = IIf(Me.CommandButton1.Caption = "隐藏答案", 8, 2)
.Execute "\([!^13]@\)", , , 1, , , , , 1, , 2 '匹配拼音
.Execute "\([一-﨩]@\)", , , 1, , , , , 1, , 2
End With
With ActiveDocument.Content.Find
.Replacement.Font.ColorIndex = 4 '1,黑色;2,蓝色;3,天兰;4,绿色;5,红色;6,红色;7,黄色;8,白色
.Replacement.Font.Name = "方正姚体"
.Execute "[\)\(]", , , 1, , , , , 1, , 2
End With
Set rg = ActiveDocument.Paragraphs(1).Range
rg.MoveEnd , -1
rg.InsertAfter vbCr
With ActiveDocument.Paragraphs(1)
istr = .Range.Text
.Range.Text = IIf(Me.CommandButton1.Caption = "隐藏答案", Left(istr, 8) & "汉字[测试版]", Left(istr, 8) & "汉字[答案版]")
.Format.Alignment = wdAlignParagraphCenter
With .Range.Font
.Bold = True
.ColorIndex = Choose(Int(Rnd * 10 + 1), wdDarkBlue, wdBlack, wdBlue, wdBrightGreen, wdDarkRed, wdGray25, wdPink, wdTeal, wdViolet, wdGreen)
.Name = Choose(Int(Rnd * 4 + 1), "腾祥范笑歌楷书简", "华文隶书", "黑体", "华文新魏")
.Size = 22
End With
With .Range
For i = 9 To .Characters.Count - 1
.Characters(i).Font.Name = "迷你简黄草"
.Characters(i).Font.Size = 13
.Characters(i).Font.ColorIndex = wdViolet
.Characters(i).Font.Italic = True
.Characters(i).Font.Line.Style = msoLineSingle
.Characters(i).Font.Line.ForeColor.RGB = RGB(0, 0, 255)
Next
End With
End With
End Sub
|
|