Hi,

I have a word document that contains words shown in the vba array
below.

The array of words in vba code are as follows ("May", "July",
"September")

I am looking for a solution where comments are added to each
occurrence of a word in the array. The comment would need to be
conditional. eg. For June the comment should have the text "Form 24
filing", For July, "IT Return Filing", for September, "Quarter
ending".

Thanks in advance for the help.

Regards,
Raj

Re: Adding comments to different words using vba by Greg

Greg
Wed Jul 16 20:42:51 PDT 2008

On Jul 16, 10:38=A0pm, Raj <rsp...@gmail.com> wrote:
> Hi,
>
> I have a word document that contains words shown in the vba array
> below.
>
> The array of words in vba code are as follows ("May", =A0"July",
> "September")
>
> I am looking for a solution where comments are added to each
> occurrence of a word in the array. The comment would need to be
> conditional. eg. For June the comment should have the text "Form 24
> filing", For July, "IT Return Filing", for September, "Quarter
> ending".
>
> Thanks in advance for the help.
>
> Regards,
> Raj


Maybe something like this:

Sub ScratchMacro()
Dim myArray(2, 1) As Variant
Dim i As Long
Dim oRng As Word.Range
For i =3D 0 To 2
myArray(i, 0) =3D Choose(i + 1, "May", "July", "September")
myArray(i, 1) =3D Choose(i + 1, "For 24 Filing", "IT Return filing",
"Quarter ending")
Next i
Set oRng =3D ActiveDocument.Range
For i =3D 0 To 2
With oRng.Find
MsgBox myArray(i, 0)
.Text =3D myArray(i, 0)
.Wrap =3D wdFindStop
While .Execute
oRng.Comments.Add oRng, myArray(i, 1)
Wend
End With
Set oRng =3D ActiveDocument.Range
Next i
End Sub

Re: Adding comments to different words using vba by Raj

Raj
Thu Jul 17 02:28:25 PDT 2008

On Jul 17, 8:42=A0am, Greg Maxey <gma...@gmail.com> wrote:
> On Jul 16, 10:38=A0pm, Raj <rsp...@gmail.com> wrote:
>
>
>
>
>
> > Hi,
>
> > I have a word document that contains words shown in the vba array
> > below.
>
> > The array of words in vba code are as follows ("May", =A0"July",
> > "September")
>
> > I am looking for a solution where comments are added to each
> > occurrence of a word in the array. The comment would need to be
> > conditional. eg. For June the comment should have the text "Form 24
> > filing", For July, "IT Return Filing", for September, "Quarter
> > ending".
>
> > Thanks in advance for the help.
>
> > Regards,
> > Raj
>
> Maybe something like this:
>
> Sub ScratchMacro()
> Dim myArray(2, 1) As Variant
> Dim i As Long
> Dim oRng As Word.Range
> For i =3D 0 To 2
> =A0 myArray(i, 0) =3D Choose(i + 1, "May", "July", "September")
> =A0 myArray(i, 1) =3D Choose(i + 1, "For 24 Filing", "IT Return filing",
> "Quarter ending")
> Next i
> Set oRng =3D ActiveDocument.Range
> For i =3D 0 To 2
> =A0 With oRng.Find
> =A0 =A0 MsgBox myArray(i, 0)
> =A0 =A0 .Text =3D myArray(i, 0)
> =A0 =A0 .Wrap =3D wdFindStop
> =A0 =A0 While .Execute
> =A0 =A0 =A0 oRng.Comments.Add oRng, myArray(i, 1)
> =A0 =A0 Wend
> =A0 End With
> =A0 Set oRng =3D ActiveDocument.Range
> Next i
> End Sub- Hide quoted text -
>
> - Show quoted text -

Thanks a ton, Greg. It worked exactly as I had in mind.

One small doubt I am asking off-hand: If instead of 3 elements, I
increase the number of elements in the array to 8, all I need to do
is to replace the 2 in the code above with 8 to make it work. Am I
right?

Regards,
Raj.

Re: Adding comments to different words using vba by Gregory

Gregory
Thu Jul 17 04:30:55 PDT 2008

Raj,

Your welcome.

No, for 8 items you would change the 2 to a 7. The first items in your list
is help in position 0. You would also of course have to add the other list
elemetns to both lines.



"Raj" <rspai9@gmail.com> wrote in message
news:ec5785e9-4df2-4e32-a49c-85a2b0bb0eb5@x35g2000hsb.googlegroups.com...
On Jul 17, 8:42 am, Greg Maxey <gma...@gmail.com> wrote:
> On Jul 16, 10:38 pm, Raj <rsp...@gmail.com> wrote:
>
>
>
>
>
> > Hi,
>
> > I have a word document that contains words shown in the vba array
> > below.
>
> > The array of words in vba code are as follows ("May", "July",
> > "September")
>
> > I am looking for a solution where comments are added to each
> > occurrence of a word in the array. The comment would need to be
> > conditional. eg. For June the comment should have the text "Form 24
> > filing", For July, "IT Return Filing", for September, "Quarter
> > ending".
>
> > Thanks in advance for the help.
>
> > Regards,
> > Raj
>
> Maybe something like this:
>
> Sub ScratchMacro()
> Dim myArray(2, 1) As Variant
> Dim i As Long
> Dim oRng As Word.Range
> For i = 0 To 2
> myArray(i, 0) = Choose(i + 1, "May", "July", "September")
> myArray(i, 1) = Choose(i + 1, "For 24 Filing", "IT Return filing",
> "Quarter ending")
> Next i
> Set oRng = ActiveDocument.Range
> For i = 0 To 2
> With oRng.Find
> MsgBox myArray(i, 0)
> .Text = myArray(i, 0)
> .Wrap = wdFindStop
> While .Execute
> oRng.Comments.Add oRng, myArray(i, 1)
> Wend
> End With
> Set oRng = ActiveDocument.Range
> Next i
> End Sub- Hide quoted text -
>
> - Show quoted text -

Thanks a ton, Greg. It worked exactly as I had in mind.

One small doubt I am asking off-hand: If instead of 3 elements, I
increase the number of elements in the array to 8, all I need to do
is to replace the 2 in the code above with 8 to make it work. Am I
right?

Regards,
Raj.