私はVBAが初めてです。パラグラフの最後に引用または文書番号が表示される長い文書がいくつかあります。幸いなことに、これらの引用とドキュメントは括弧で囲まれているため、簡単に分離できます。これらの括弧の内容 (括弧自体を含む) を各段落の先頭に移動し、閉じ括弧の後に 2 つのスペースを追加する必要があります。
例えば:
これは段落 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