新人初学,word宏 修改字体用,一次大概10w个字左右,运行最快都要10分钟,最慢就直接卡死,请大佬不吝赐教
Sub 随机模仿手写()
Dim Ra As Range
Dim FontSize() As String
FontSize = Split("16.5,16.5,17,18", ",")
Dim FontName() As String
FontName = Split("A1,A2,A3,A4,A5", ",")
a = 0
'a值调整字体上下的偏差
b = 1
'b值调整字间距
'c = 20
'c值调整行间距
For Each Ra In ActiveDocument.Characters
VBA.Randomize
FontNameLength = UBound(FontName) - LBound(FontName)
FontSizeLength = UBound(FontSize) - LBound(FontSize)
Ra.Font.Name = FontName(Int(VBA.Rnd * FontNameLength) + 1)
Ra.Font.Size = FontSize(Int(VBA.Rnd * FontSizeLength) + 1)
Ra.Font.Position = Choose(Int(VBA.Rnd * 0.5) + 1, -1, -0.5, 0, 0.5, 1) + a
Ra.Font.Spacing = Choose(Int(VBA.Rnd * 1) + 1, -1.5, -1, -0.5, 0, 0.5, 1, 2) + b
If Ra = "。" Or Ra = "," Or Ra = ";" Or Ra = "’" Or Ra = "‘" Or Ra = "“" Or Ra = "”" Or Ra = "!" Or Ra = ":" Then
'Ra.Font.Name = "A1"
Ra.Font.Size = "14"
Ra.Font.Position = "-0.5"
Ra.Font.Spacing = "-1"
'ElseIf Asc(Ra) >= 48 And Asc(Ra) <= 57 Then
' Ra.Font.Name = "J2,J3,J4"
ElseIf Asc(Ra) >= 97 And Asc(Ra) <= 122 Or Asc(Ra) >= 65 And Asc(Ra) <= 90 Or Ra = " . " Or Ra = "(" Or Ra = ")" Or Ra = "(" Or Ra = ")" Or Ra = "~" Then
'Ra.Font.Name = "J1,J2,J3,J4,J5,A1,A2,A3"
End If
If Ra = "." Or Ra = "状" Then
Ra.Font.Name = "A3"
Ra.Font.Size = "16.5"
Ra.Font.Position = "0"
Ra.Font.Spacing = "0"
End If
If Ra = "," Or Ra = "、" Then
Ra.Font.Name = "A3"
Ra.Font.Size = "16.5"
Ra.Font.Position = "0"
Ra.Font.Spacing = "-5"
End If
If Ra = "0" Or Ra = "、" Then
Ra.Font.Size = "11"
Ra.Font.Position = "0"
Ra.Font.Spacing = "0"
End If
If Ra = "顶" Then
Ra.Font.Name = "W3"
Ra.Font.Size = "16.5"
Ra.Font.Position = "0"
Ra.Font.Spacing = "0"
End If
Next
'For Each Ra In ActiveDocument.Paragraphs
' Ra.ParagraphStyle.LineSpacingRule = wdLineSpaceExactly
' Ra.ParagraphStyle.LineSpacing = Int(VBA.Rnd * 1) + 1 + c
' Next
'With Selection.ParagraphFormat
' .FirstLineIndent = CentimetersToPoints(0.35)
' .CharacterUnitFirstLineIndent = 0
' End With
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "“"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute2007 Replace:=ReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "”"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Application.ScreenUpdating = False
End Sub