Re: First sentence check
- From: Pesach Shelnitz <pesach18(AT)hotmail.com>
- Date: Thu, 17 Sep 2009 01:14:01 -0700
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
--
Hope this helps,
Pesach Shelnitz
"Pesach Shelnitz" wrote:
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.
--
Hope this helps,
Pesach Shelnitz
"Sahana" wrote:
On Sep 16, 4:18 pm, Pesach Shelnitz <pesach18(AT)hotmail.com> wrote:
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
"Sahana" wrote:
On Sep 15, 10:39 pm, Pesach Shelnitz <pesach18(AT)hotmail.com> wrote:
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
"Sahana" wrote:
On Sep 15, 1:18 pm, Pesach Shelnitz <pesach18(AT)hotmail.com> wrote:
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
"Sahana" wrote:
I found an interesting post in
http://groups.google.com/group/microsoft.public.word.vba.general/brow...
I tired to run the macro. I worked great. But I would love to have the
word "various" alone highlighted. Plus, the first lead in sentence is
highlighted the rest of the document is ignored. Can someone help me
through this?- Hide quoted text -
- 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- Hide quoted text -
- 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?- Hide quoted text -
- 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
- References:
- First sentence check
- From: Sahana
- RE: First sentence check
- From: Pesach Shelnitz
- Re: First sentence check
- From: Sahana
- Re: First sentence check
- From: Pesach Shelnitz
- Re: First sentence check
- From: Sahana
- Re: First sentence check
- From: Pesach Shelnitz
- Re: First sentence check
- From: Sahana
- Re: First sentence check
- From: Pesach Shelnitz
- First sentence check
- Prev by Date: RE: Return focus to Word 2007 after launching from msAccess
- Next by Date: Re: closing documents in 2007 versus 2003
- Previous by thread: Re: First sentence check
- Next by thread: Acroymns
- Index(es):
Relevant Pages
|