Comments

S

Sahana

I m trying to use comments. The word I want the macros to select for
comment is Name:

But when I type Name: (with the colons on) the macros continue to
select that I find that strange.

Also macros are checking the name: (notice small caps) which i dont
want to happen.

Any solution for this?

Plus is it possible to use the .find property and then use the
comments, instead of the place where the word is being highlighted?


I hope someone can help me thru this.



Sahana
 
G

Graham Mayor

Your question makes no sense. We cannot see your macro or your document. Can
you explain *exactly* what you are trying to do.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
S

Sriram

Your question makes no sense. We cannot see your macro or your document. Can
you explain *exactly* what you are trying to do.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>










- Show quoted text -


I have placed the code below.

Trying running the code with the sample data.

Name: Sahana
Name Sahana

Macros highlight both instances of "Name".

Can something be added to tweak the code? Or atleast some kinda
exception be created like if the macros encounter Name then no need to
look into that word?


Sahana
 
G

Graham Mayor

You have not included the code?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
S

Sahana

You have not included the code?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>










- Show quoted text -


The code would be this

Sub comments()
'
' dsds Macro
'
'
Dim vFindText As Variant
Dim i As Long
vFindText = Array("name")
For i = 0 To UBound(vFindText)
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
Do While .Execute(findText:=vFindText(i), _
Forward:=True)
Selection.comments.Add _
Range:=Selection.Range, Text:="change"
Loop
End With
End With
Next
End Sub
 
G

Graham Mayor

If I understand your requirement - Sub comments()
'
' dsds Macro
'
'
Dim vFindText As Variant
Dim i As Long
Dim oRng As Range
vFindText = Array("Name:")
For i = 0 To UBound(vFindText)
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
Do While .Execute(findText:=vFindText(i), _
Forward:=True, _
MatchCase:=True)
Set oRng = Selection.Range
oRng.End = oRng.End - 1
oRng.Comments.Add _
Range:=oRng, Text:="change"
Loop
End With
End With
Next
End Sub

will work to find Name: and comment the part Name (without the colon),
however you don't need an array for just one term. The following will work
for one term

Dim vFindText As String
Dim i As Long
Dim oRng As Range
vFindText = "Name:"
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
Do While .Execute(findText:=vFindText, _
Forward:=True, _
MatchCase:=True)
Set oRng = Selection.Range
oRng.End = oRng.End - 1
oRng.Comments.Add _
Range:=oRng, Text:="change"
Loop
End With
End With

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
S

Sahana

If I understand your requirement - Sub comments()
'
' dsds Macro
'
'
Dim vFindText As Variant
Dim i As Long
Dim oRng As Range
vFindText = Array("Name:")
For i = 0 To UBound(vFindText)
    With Selection
        .HomeKey wdStory
        With .Find
            .ClearFormatting
            Do While .Execute(findText:=vFindText(i), _
                Forward:=True, _
                MatchCase:=True)
                Set oRng = Selection.Range
                oRng.End = oRng.End - 1
                oRng.Comments.Add _
                      Range:=oRng, Text:="change"
             Loop
        End With
    End With
Next
End Sub

will work to find Name: and comment the part Name (without the colon),
however you don't need an array for just one term. The following will work
for one term

Dim vFindText As String
Dim i As Long
Dim oRng As Range
vFindText = "Name:"
With Selection
    .HomeKey wdStory
    With .Find
        .ClearFormatting
        Do While .Execute(findText:=vFindText, _
            Forward:=True, _
            MatchCase:=True)
            Set oRng = Selection.Range
            oRng.End = oRng.End - 1
            oRng.Comments.Add _
                  Range:=oRng, Text:="change"
         Loop
    End With
End With

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>






- Show quoted text -

A small hitch I found. If I were to replace Name: with Name in the
macro. The macros highlight Name: as well that is (name) part alone.

Can macros be tweaked or something so that Name in Name: will not be
highlighted if vFindText = "Name:" is changed as vFindText = "Name"


I wish to get some help here


Thanks
 
G

Graham Mayor

If you want to process Name only when it is not followed by a colon, then
you need to look at the character that follows the found string and evaluate
it - something like

Dim i As Long
Dim oRng As Range
vFindText = "Name"
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
Do While .Execute(findText:=vFindText, _
Forward:=True, _
MatchCase:=True)
Set oRng = Selection.Range 'oRng is the found text
oRng.End = oRng.End + 1 'add the next character
If oRng.Characters.Last <> ":" Then 'check if it is a colon
oRng.End = oRng.End - 1 'it isn't, so remove the last
character
oRng.Comments.Add _
Range:=oRng, Text:="change" 'and add the comment
End If
Loop
End With
End With


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top