如何仅替换字符串 VBA 中的起始行
How to replace String only Starting line with in VBA
如何在 MS Word 中用起始行替换字符串
例子
The Statue of Liberty of New York was (a) gifted by which country?
(a) Britain
(b) France
(c) Germany
(d) Spain
这里的(a)只需要替换成Line Starting的(A)
输出像
The Statue of Liberty of New York was (a) gifted by which country?
(A) Britain
(b) France
(c) Germany
(d) Spain
With Selection.Find
.Text = "^\(a\)"
.Replacement.Text = "(A)"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
此代码将段落开头的所有 (a)
替换为 (A)
:
Sub ReplA()
With ActiveDocument.Range
.Find.Text = "(a)"
Do While .Find.Execute
If .Start = .Paragraphs(1).Range.Start Then .Text = "(A)"
Loop
End With
End Sub
之前
(a) first line
The Statue of Liberty of New York was (a) gifted by which country?
(a) Britain
(b) France
(c) Germany
(d) Spain (a)
(a) will also be changed
之后
(A) first line
The Statue of Liberty of New York was (a) gifted by which country?
(A) Britain
(b) France
(c) Germany
(d) Spain (a)
(A) will also be changed
如何在 MS Word 中用起始行替换字符串 例子
The Statue of Liberty of New York was (a) gifted by which country?
(a) Britain
(b) France
(c) Germany
(d) Spain
这里的(a)只需要替换成Line Starting的(A)
输出像
The Statue of Liberty of New York was (a) gifted by which country?
(A) Britain
(b) France
(c) Germany
(d) Spain
With Selection.Find
.Text = "^\(a\)"
.Replacement.Text = "(A)"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
此代码将段落开头的所有 (a)
替换为 (A)
:
Sub ReplA()
With ActiveDocument.Range
.Find.Text = "(a)"
Do While .Find.Execute
If .Start = .Paragraphs(1).Range.Start Then .Text = "(A)"
Loop
End With
End Sub
之前
(a) first line
The Statue of Liberty of New York was (a) gifted by which country?
(a) Britain
(b) France
(c) Germany
(d) Spain (a)
(a) will also be changed
之后
(A) first line
The Statue of Liberty of New York was (a) gifted by which country?
(A) Britain
(b) France
(c) Germany
(d) Spain (a)
(A) will also be changed