0
Word文書のすべての段落を実行し、すべての段落にコメントを追加するMicrosoft Word VBAマクロを作成しています。そのコメントにはその段落のスタイルが含まれます。このようにして、同僚はコメント付きの文書を印刷して、今後同様の文書をスタイルする方法を知ることができます。Wordマクロ文書にコメントを追加できない
私はほとんどそこだ、コードがすべての段落にコメントが追加されますが、表の最初の行で死ぬ:
「オブジェクトは終わりを意味しているため、このメソッドまたはプロパティは使用できません。テーブル行の
ここではコードです:
Sub aa_AddStylesComment()
'
' aa_AddStylesComment Macro
' Author: Me!
'
Dim strParaStyle As String
Dim cmtNewComment As Comment
'Run through word file and delete any comments with author set to a space character (that is the author of the comments added by the script)
For J = ActiveDocument.Comments.Count To 1 Step -1
With ActiveDocument
If .Comments(J).Author = " " Then
.Comments(J).Delete
End If
End With
Next J
'Running through every paragraph
For i = 1 To ActiveDocument.Paragraphs.Count
With ActiveDocument
'Get paragraph style
strParaStyle = .Paragraphs(i).Style
'Create a new comment and collect it - then change the author to space character
Set cmtNewComment = Selection.Comments.Add(.Range(.Paragraphs(i).Range.Words(1).Start, (.Paragraphs(i).Range.Words(1).End - 1)), strParaStyle)
cmtNewComment.Author = " "
End With
Next
End Sub