【Word VBA】一括置換による翻訳にて原文データを見ながら翻訳する(その2)

2012年6月12日

先日、原文データを見ながら翻訳するためのマクロ をご紹介しました。

このときは、段落ごとに隠し文字として原文データを表示させる方法をご紹介しました。

ぱらぱらを使えば、上書き翻訳のときに原文データを見ながら、翻訳文を作ることができます。

詳細は、上記記事をご覧ください。

今回は、文章ごとに隠し文字を挿入する方法です。

新規文書で作成しますので、もとの文章に書き込むわけではありません。

このマクロでできること

文書を開いた状態でマクロを実行すると、1文1文に対して、隠し文字を挿入します。

マクロ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
Sub 上書き翻訳用のデータ作成マクロ_文章()
 
 Dim myDoc As Document
 Dim orgDoc As Document
 Dim myParaNum As Long
 Dim i As Long
 Dim myPosition As Long
 
 Set orgDoc = ActiveDocument
 Set myDoc = Documents.Add
 
 myParaNum = orgDoc.sentences.Count
 
 Application.ScreenUpdating = False
 
 For i = 1 To myParaNum
  orgDoc.sentences(i).Copy
 
  With Selection
   '貼り付け
   myPosition = .Start
   .Paste
   .Start = myPosition
   With .Font
    .ColorIndex = wdBlue
    .Hidden = True
   End With
   .Collapse direction:=wdCollapseEnd
   '貼り付け
   .Font.ColorIndex = wdAuto
   .Paste
  End With
 
 Next i
 
 Selection.HomeKey Unit:=wdStory
 
 Set orgDoc = Nothing
 Set myDoc = Nothing
 
 Application.ScreenUpdating = True
 
End Sub

-コード
-,

S