在前面插入一个 Space 和斜体字
Inserting a Space Before and Italicized Word
我有一个 Word 文档,其中包含数百个斜体字,它们与前一个字之间没有 space。
例如:
敏捷棕色狐狸跳过懒惰狗.
我要找的结果是:
敏捷的棕色狐狸跳过懒惰的狗.
我一直在尝试使用查找和替换和 .InsertBefore
构建一个宏来为我解决这个问题,但没有成功。
这是我目前的代码。
Sub FindItalics()
Selection.Find.ClearFormatting
Selection.Find.Font.Italic = True
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
InsertBefore
End Sub
Sub InsertBefore()
With Selection
.InsertBefore " "
End With
End Sub
我发现这行得通并且可以满足我的要求,但是它只对文档中的第一个斜体字起作用,不会在文档的其余部分继续。
我认为你可以在没有 VBA 的情况下做到这一点:
在 Word 的 Find/Replace 中打开通配符搜索,搜索格式、字体...、斜体并搜索模式 (*>)
。
*
表示找到任何东西,
>
表示查找到词尾,
()
括号将在模式匹配时创建一个自动编号的组。
在“替换”框中,不要更改格式并替换为文本:<space>
以插入 space 后跟第 1 组。
这对我有用:
Sub FindItalics()
Dim rng As Range
Set rng = Selection.Range
With rng.Find
.Text = ""
.Replacement.Text = ""
.ClearFormatting
.Wrap = wdFindStop
.Format = True
.Font.Italic = True
.MatchWholeWord = False
.Forward = True
While .Execute
'Note: 'rng' is now the range containing the matched content
rng.InsertBefore " "
rng.Collapse wdCollapseEnd
Wend
End With
End Sub
我有一个 Word 文档,其中包含数百个斜体字,它们与前一个字之间没有 space。
例如:
敏捷棕色狐狸跳过懒惰狗.
我要找的结果是:
敏捷的棕色狐狸跳过懒惰的狗.
我一直在尝试使用查找和替换和 .InsertBefore
构建一个宏来为我解决这个问题,但没有成功。
这是我目前的代码。
Sub FindItalics()
Selection.Find.ClearFormatting
Selection.Find.Font.Italic = True
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
InsertBefore
End Sub
Sub InsertBefore()
With Selection
.InsertBefore " "
End With
End Sub
我发现这行得通并且可以满足我的要求,但是它只对文档中的第一个斜体字起作用,不会在文档的其余部分继续。
我认为你可以在没有 VBA 的情况下做到这一点:
在 Word 的 Find/Replace 中打开通配符搜索,搜索格式、字体...、斜体并搜索模式 (*>)
。
*
表示找到任何东西,
>
表示查找到词尾,
()
括号将在模式匹配时创建一个自动编号的组。
在“替换”框中,不要更改格式并替换为文本:<space>
以插入 space 后跟第 1 组。
这对我有用:
Sub FindItalics()
Dim rng As Range
Set rng = Selection.Range
With rng.Find
.Text = ""
.Replacement.Text = ""
.ClearFormatting
.Wrap = wdFindStop
.Format = True
.Font.Italic = True
.MatchWholeWord = False
.Forward = True
While .Execute
'Note: 'rng' is now the range containing the matched content
rng.InsertBefore " "
rng.Collapse wdCollapseEnd
Wend
End With
End Sub