First sentence check

P

Pesach Shelnitz

Hi Sahana,

To change the macro so that only the word "various" would be highlighted,
you first
need to add an Integer variable for the return value from the call to Instr.
For
example, add the following line to the declarations at the beginning of the
macro.

Dim pos As Integer

Then change the If statements with a call to Instr to the following (make
sure that you include the additional line before the new If statement):

pos = InStr(1, .Text, "various", vbTextCompare)
If pos > 0 Then
.MoveStart wdCharacter, pos - 1
.End = .start + Len("various")
ActiveDocument.Comments.Add Range:=oRng, Text:="AVOID"
End If

You can add similar code to search for and highlight other words or
expressions,
such as "as follows".

This macro may not processi all the lists in a doc because it is based on
the Lists
collection. The members of the Lists collection are List objects. Each List
object can
include what appears to be more than one list in your document.
 
S

Sahana

Hi Sahana,

To change the macro so that only the word "various" would be highlighted,
you first
need to add an Integer variable for the return value from the call to Instr.
For
example, add the following line to the declarations at the beginning of the
macro.

Dim pos As Integer

Then change the If statements with a call to Instr to the following (make
sure that you include the additional line before the new If statement):

        pos = InStr(1, .Text, "various", vbTextCompare)
        If pos > 0 Then
            .MoveStart wdCharacter, pos - 1
            .End = .start + Len("various")
            ActiveDocument.Comments.Add Range:=oRng, Text:="AVOID"
        End If

You can add similar code to search for and highlight other words or
expressions,
such as "as follows".

This macro may not processi all the lists in a doc because it is based on
the Lists
collection. The members of the Lists collection are List objects. Each List
object can
include what appears to be more than one list in your document.

--
Hope this helps,
Pesach Shelnitz






- Show quoted text -

Cant something be done to check for the presence of rest of the list
present in the doc? Or is it just impossible
 
P

Pesach Shelnitz

Hi Sahana,

I have found that if bulleted lists are created in the following way, the
macro will find the line before every lists.
1) Before typing the leading line, press Shift+Ctrl+N to set its style to
Normal or set its style to a another style that is not bulleted or numbered.
2) Press Enter at the end of the leading line.
3) Click the control for bulleting, type each item and press Enter at the
end of each line.
4) When you want to end the list, on a new bulleted line, press Shift+Ctrl+N
to set its style to Normal or set the style to a another style that is not
bulleted or numbered.
5) Repeat steps 1-4 for each new list.

How are you creating the bulleted lists?
 
S

Sahana

Hi Sahana,

I have found that if bulleted lists are created in the following way, the
macro will find the line before every lists.
1) Before typing the leading line, press Shift+Ctrl+N to set its style to
Normal or set its style to a another style that is not bulleted or numbered.
2) Press Enter at the end of the leading line.
3) Click the control for bulleting, type each item and press Enter at the
end of each line.
4) When you want to end the list, on a new bulleted line, press Shift+Ctrl+N
to set its style to Normal or set the style to a another style that is not
bulleted or numbered.
5) Repeat steps 1-4 for each new list.

How are you creating the bulleted lists?

--
Hope this helps,
Pesach Shelnitz






- Show quoted text -

I do it more or less similar fashion only. If thats the case, then
macros should check for all lists present in the document
unfortunately it does not. Can you suggest a way to solve this tricky
suitation?
 
P

Pesach Shelnitz

Hi Sahana,

Run the macro ShowLists that I sent you in your post called "Error"
(http://www.microsoft.com/communitie...e963&mid=b91e699a-ab21-4c8f-951c-e90a76f9987f).
It will show how many lists Word finds in your document. From the results,
you should be able to determine which lists need to be broken up into
separate lists. If you need to break up a list into two lists, select the
applicable list items for one of the lists, press Shift+Ctrl+N to apply the
Normal style or apply a non-list style, then apply bulleting or a style with
bulleting. Then run the macro again to see the result.
 
S

Sahana

Hi Sahana,

Run the macro ShowLists that I sent you in your post called "Error"
(http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?&l...).
It will show how many lists Word finds in your document. From the results,
you should be able to determine which lists need to be broken up into
separate lists. If you need to break up a list into two lists, select the
applicable list items for one of the lists, press Shift+Ctrl+N to apply the
Normal style or apply a non-list style, then apply bulleting or a style with
bulleting. Then run the macro again to see the result.

--
Hope this helps,
Pesach Shelnitz






- Show quoted text -

Hi I just tried to record equivalent of Shift + ctrl +N , I found that
Selection.Range.Style = ActiveDocument.Styles(wdStyleNormal) is the
equivalent.

Is it possible or sensible to add this Selection.Range.Style =
ActiveDocument.Styles(wdStyleNormal) first and then start the macro?
Do u think ll that be a good option.

I have tired something of that sort below, you can ofcourse help me in
improving that. But the amcros i tried just oesnt work. hope u help
me

Sub jf()


Dim lList As Long
Dim oRng As Range


For lList = ActiveDocument.Lists.Count To 1 Step -1
Set oRng = ActiveDocument.Lists(lList).ListParagraphs(1).Range
Selection.Range.Style = ActiveDocument.Styles(wdStyleNormal)
With oRng
.Collapse Direction:=wdCollapseStart
.MoveStart Unit:=wdSentence, Count:=-1
.MoveEnd Unit:=wdCharacter, Count:=-1
If .Characters.Last <> ":" Then
.InsertAfter Text:=":"
End If
If InStr(1, .Text, "various") Then
ActiveDocument.comments.Add Range:=oRng, Text:="AVOID"
If InStr(1, .Text, "as follows") Then
ActiveDocument.comments.Add Range:=oRng, Text:="AVOID"
End If
End If
End With
Next lList


End Sub
 
P

Pesach Shelnitz

Hi Sahana,

The line that you added applies the Normal style only to the Selection
object, which is the insertion point when the macro is launched or the text
that is selected when the macro is launched. The macro repeats this action
for every ListParagraph, but repeating this action does not change anything
because the Selection is never changed.

In my opinion, what you need is a way to determine whether the paragraph
before each ListParagraph is a ListParagraph. If it is not a ListParagraph,
then it is the leading paragraph that you want to test for the presence of a
colon at the end and the presence of the words "various" and "following."

If the leading paragraphs had a specific style that is not applied to other
paragraphs, this would be a simple problem and there would be no need to look
at the lists at all, but with unpredictable styles in every paragraph, this
is a fairly complex problem.
 
P

Pesach Shelnitz

Hi Sahana,

I thought over what I wrote in the second paragraph of my previous post and
realized how to fix the macro to find the leading sentences even if a List
object includes more than one list. Try this new version.

Sub LineBeforeList()
Dim i As Long
Dim j As Long
Dim myRange As Range
Dim pos As Integer

With ActiveDocument
For i = .ListParagraphs.Count To 1 Step -1
Set myRange = .ListParagraphs(i).Range
If i > 1 Then
j = i - 1
Else
If myRange.start < 2 Then
Exit For
End If
j = i
End If
If myRange.start <> .ListParagraphs(j).Range.End Then
With myRange
.Collapse Direction:=wdCollapseStart
.MoveStart Unit:=wdSentence, Count:=-1
.MoveEnd Unit:=wdCharacter, Count:=-1
If .Characters.Last <> ":" Then
.InsertAfter Text:=":"
End If
pos = InStr(1, .Text, "various", vbTextCompare)
If pos > 0 Then
.MoveStart wdCharacter, pos - 1
.End = .start + Len("various")
ActiveDocument.Comments.Add _
Range:=myRange, Text:="AVOID"
End If
pos = InStr(1, .Text, "following", vbTextCompare)
If pos > 0 Then
.MoveStart wdCharacter, pos - 1
.End = .start + Len("following")
ActiveDocument.Comments.Add _
Range:=myRange, Text:="AVOID"
End If
End With
End If
Next
End With
Set myRange = Nothing
End Sub
 

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