我使用word打开(特殊)html文档进行打印,并想编写一个脚本来解决一个小问题:
在html文件中,我将“15厘米”这样的数字写为“15厘米”,因此数字“15”和单位“厘米”之间不会有换行符。
我的问题是:间距太宽,尤其是当单词扩展空格以适应句子的边缘时。
所以我想使用 Word VBA 脚本将它们替换为某种细空格。我想我需要枚举这些段落,但我不确定如何替换其中的文本。这是我到目前为止想到的,但我不知道如何在word中编写html nbsp以及在薄空间中使用什么,也许有人可以在这里帮助我?
Sub MakeThinSpaces()
Dim para As Paragraph
For Each para In ActiveDocument.Paragraphs
replace the with some   here?
Next
End Sub
Run Code Online (Sandbox Code Playgroud)
细空格是 Unicode 8201。(窄的不间断空格是 8239)。它应该使用选择对象来处理此代码。
^s是受保护空间的通配符,您也可以使用Chr(160)
Selection.WholeStory
With Selection.Find
.Text = "^s"
.Replacement.Text = ChrW(8201)
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
Run Code Online (Sandbox Code Playgroud)