S
Sam
This is going to sound strange, but I have a piece of code that was given to me in answer to a question a while ago (not on this forum), but the code isn't complete, and I can't figure out how to make it work.
I have a document (C:\mycomments.doc) that contains a table with words or sentences on one side, and comments on the other. I want to use this document in such a way that I can look for any instance of the left-hand phrases in my active document, and insert the comments that appear to the right at that point in the active document.
The below code looks good, but nowhere is "DataDocument" defined. How do I set DataDocument = C:\mycomments.doc?
Thanks!
VB:
--------------------------------------------------------------------------------
Sub addComments()
Dim r As Range
Dim mySearchText As String
Dim myCommentText As String
For i = 1 To DataDocument.Tables(1).Rows.Count
mySearchText = DataDocument.Tables(1).Cell(i, 1).Range.Text
myCommentText = DataDocument.Tables(1).Cell(i, 2).Range.Text
Set r = ActiveDocument.Range
With r.Find
.Text = mySearchText
.Forward = True
.Wrap = wdFindStop
.MatchWholeWord = True
Do While .Execute
ActiveDocument.Comments.Add Range:=r, _
Text:=myCommentText
Loop
End With
Next i
End Sub
I have a document (C:\mycomments.doc) that contains a table with words or sentences on one side, and comments on the other. I want to use this document in such a way that I can look for any instance of the left-hand phrases in my active document, and insert the comments that appear to the right at that point in the active document.
The below code looks good, but nowhere is "DataDocument" defined. How do I set DataDocument = C:\mycomments.doc?
Thanks!
VB:
--------------------------------------------------------------------------------
Sub addComments()
Dim r As Range
Dim mySearchText As String
Dim myCommentText As String
For i = 1 To DataDocument.Tables(1).Rows.Count
mySearchText = DataDocument.Tables(1).Cell(i, 1).Range.Text
myCommentText = DataDocument.Tables(1).Cell(i, 2).Range.Text
Set r = ActiveDocument.Range
With r.Find
.Text = mySearchText
.Forward = True
.Wrap = wdFindStop
.MatchWholeWord = True
Do While .Execute
ActiveDocument.Comments.Add Range:=r, _
Text:=myCommentText
Loop
End With
Next i
End Sub