|
发表于 2023-1-28 01:31:24
|
显示全部楼层
Sub 字体点窜()
' 字体点窜 宏
Dim R_Character As Range
' 字体巨细在以下值之间停止波动,改成需要的巨细,反复出现的次数越多,响应出现的几率越大,最小精度0.5
Dim FontSize() As String
FontSize = Split("18.5,18.5,18.5,19,18", ",")
'字体称号在以下字体之间停止波动,改成需要的字体,但需要保证系统具有以下字体,可以在word检察字体名字
Dim FontName() As String
FontName = Split("【嵐】芊柔体,萌妹子体,张维镜手写楷书,【嵐】芊柔体", ",")
' 保举字体
' "萌妹子体,张维镜手写楷书,萌妹子体,汉仪晨妹子W,小豆岛风景诗简繁,小豆岛秋天和简繁"
'a数值越大,行距越大,波动范围a+x, x∈[-1~1]
a = 0
'b数值越大,字距越大,波动范围b+x, x∈[-1~1]
b = 0
'行间距 在一定以下值中均等散布,改成需要的巨细,范围c+x, x∈[0~5]
c = 25
For Each R_Character In ActiveDocument.Characters
VBA.Randomize
' 数组长度
FontNameLength = UBound(FontName) - LBound(FontName)
FontSizeLength = UBound(FontSize) - LBound(FontSize)
' 字号巨细
R_Character.Font.Size = FontSize(Int(VBA.Rnd * FontSizeLength) + 1)
' 字的高低偏移
R_Character.Font.Position = Choose(Int(VBA.Rnd * 5) + 1, -1, -0.5, 0, 0.5, 1) + a
' 字的左右间距
R_Character.Font.Spacing = Choose(Int(VBA.Rnd * 5) + 1, -1, -0.5, 0, 0.5, 1) + b
If R_Character = "。" Or R_Character = "," Or R_Character = "," Or R_Character = ";" Or R_Character = "’" Or R_Character = "‘" Or R_Character = "“" Or R_Character = "”" Or R_Character = "!" Or R_Character = "?" Or R_Character = "、" Or R_Character = ":" Then
' 中文常用标点标记
' 标点牢固用以下字体
R_Character.Font.Name = "张维镜手写楷书"
' 标点随机用FontName中字体
'R_Character.Font.Name = FontName(Int(VBA.Rnd * FontSizeLength))
ElseIf Asc(R_Character) >= 48 And Asc(R_Character) <= 57 Then
&#39; 数字
R_Character.Font.Name = &#34;【嵐】芊柔体&#34;
ElseIf Asc(R_Character) >= 97 And Asc(R_Character) <= 122 Or Asc(R_Character) >= 65 And Asc(R_Character) <= 90 Or R_Character = &#34;.&#34; Or R_Character = &#34;(&#34; Or R_Character = &#34;)&#34; Or R_Character = &#34;(&#34; Or R_Character = &#34;)&#34; Then
&#39; 巨细写字母
R_Character.Font.Name = &#34;【嵐】芊柔体&#34;
End If
Next
For Each Cur_Paragraph In ActiveDocument.Paragraphs
&#39; 设备行间距范例为牢固值
Cur_Paragraph.LineSpacingRule = wdLineSpaceExactly
&#39; 设备行间距的值
Cur_Paragraph.LineSpacing = Int(VBA.Rnd * 5) + 1 + c
Next
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = &#34;“&#34;
.Replacement.Text = &#34;&#34;
.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
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = &#34;”&#34;
.Replacement.Text = &#34;&#34;
.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 = True
End Subp.s. 字体下载好后,将ttf文件复制到C:\Windows\Fonts即可完成安装。 |
|