新人初学,word宏 修改字体用,一次大概10w个字左右,运行最快都要10分钟,最慢就直接卡死,请大佬不吝赐教

qq_37179700 qq_37179700 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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



...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
qq_37179700
VBA 2,506 成员 10,830 内容