我是 VBA 新手。我有几个长文档,其中引文或文档编号出现在段落的末尾。幸运的是,这些引文和文件都用括号括起来,这应该很容易隔离。我需要将这些括号的内容(包括括号本身)移动到每个段落的前面,然后在右括号后添加两个空格。
例如:
这是我在第 1 段中的文字。(http://nytimes.com)
这是我在第 2 段中的文字。(1.b.3B)
应该看起来像:
( http://nytimes.com ) 这是我在第 1 段中的文字。
(1.b.3B) 这是我在第 2 段中的文字。
我发现以下链接中的答案很有用,但似乎无法将其应用于我的案例:Get paragraph no where txt is found, and move text to end of paragraph using Word 2010 vba
提前谢谢了。
这是我到目前为止所拥有的,但脚本似乎没有运行:
Sub Test1()
Dim currDoc As Document
Set currDoc = ActiveDocument
Dim docRng As Range, currRng As Range, strRng As Range
Set docRng = ActiveDocument.Content
Dim currPara As Paragraph
Dim strText As String
Selection.HomeKey Unit:=wdStory ' Start from the beginning of the doc.
For Each currPara In docRng.Paragraphs ' Loop through the paragraphs in the active document.
Set currRng = currDoc.Range(currPara.Range.Start, currPara.Range.End) ' Selects the current paragraph, so that the search is conducted paragraph by paragraph.
With Selection.Find
.ClearFormatting
.Text = "\(*\)"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
If currRng.Find.Execute Then
With Selection
.Select
.Cut
.StartOf Unit:=wdParagraph
.Paste
.InsertAfter " "
End With
End If
Next currPara
End Sub