Error

S

Sahana

I have this macro which checks for the presence of "and" at the end of
a bullet list. But macro is wrongly highlights this which is in a
table format. I ll try my level best in recreating this here


1 Define Proactive Mark Response At the end of this session, you
will be able to define
1 Uses of Drill-Down Analysis this session, you will be
able

So the table has 2 rows and 2 coloums. First columns will have the 1
there (one below the other in form of rows), second coloumn will have
Define Proactive Mark Response and Uses of Drill-Down Analysis (one
below the other in form of rows) The third coloum is has At the end of
this session, you will be able to define and this session, you will
be able (one below the other in form of rows)


Kindly help me with this


Sahana
 
P

Pesach Shelnitz

Hi Sahana,

This question is a bit confusing. You start out by talking about a bulleted
list without describing its contents, and then you describe the contents of a
table. You also mention a macro that doesn't perform the way you would like,
but you didn't include the code. I don't think that anyone can help you
without more information.
 
S

Sahana

Hi Sahana,

This question is a bit confusing. You start out by talking about a bulleted
list without describing its contents, and then you describe the contents of a
table. You also mention a macro that doesn't perform the way you would like,
but you didn't include the code. I don't think that anyone can help you
without more information.

--
Hope this helps,
Pesach Shelnitz









- Show quoted text -

Macros check for presence of and at the end of the bullet list. I had
the document with bullet list. And very incidently the document has
this table shown below. Pls try to recreate the table.

The table 3 coloums and 2 rows.

Ist coloumn 1 row has S.No
1st coloum 2 row has 1.

2nd Col 1 row has Date
2nd col 2 row has Date: September 9, 2009

3rd col 1 row has Description
3rd col 2 row has Modified.

Please place this in any documet and run the macro pasted below.

Sub conjuction()
Dim i As Long
Dim j As Long
Dim pos As Integer
Dim searchText As String
Dim myRange As Range


searchText = "and"
With ActiveDocument
For j = 1 To .Lists.Count
For i = 1 To .Lists(j).ListParagraphs.Count
Set myRange = .Lists(j).ListParagraphs(i).Range
pos = InStrRev(myRange.Text, searchText, -1, _
vbTextCompare)
If pos > Len(myRange.Text) - 6 Then
myRange.Start = myRange.Start + pos - 1
myRange.End = myRange.Start + Len(searchText)
myRange.Select
Selection.comments.Add _
Range:=Selection.Range, Text:="Do not use
""and"" in a bullet list"

End If
Selection.Collapse Direction:=wdCollapseStart

Next
Next
End With
End Sub



I dont understand the word and does it exist in the table yet the
error is displayed. This is so illogical. There should be a way out to
this. Pls can you direct me through this?
 
P

Pesach Shelnitz

Hi Sahana,

I created the table that you described in a new document and ran the macro.
It did not create any comments. I suspect that your document may have a list
in it. Please run the following macro from you document to see if it contains
anything that Word regards as a list.

Sub ShowLists()
Dim i As Long
Dim j As Long
Dim myString As String

myString = ""
With ActiveDocument
If .Lists.Count > 0 Then
For j = 1 To .Lists.Count
myString = myString & vbCrLf & _
"List " & j & " contains " & _
.Lists(j).ListParagraphs.Count & _
" items:" & vbCrLf
For i = 1 To .Lists(j).ListParagraphs.Count
myString = myString & _
.Lists(j).ListParagraphs(i).Range.Text
Next
Next
MsgBox myString
Else
MsgBox "There are no lists in the document."
End If
End With
End Sub
 
S

Sahana

Hi Sahana,

I created the table that you described in a new document and ran the macro.
It did not create any comments. I suspect that your document may have a list
in it. Please run the following macro from you document to see if it contains
anything that Word regards as a list.

Sub ShowLists()
    Dim i As Long
    Dim j As Long
    Dim myString As String

    myString = ""
    With ActiveDocument
        If .Lists.Count > 0 Then
            For j = 1 To .Lists.Count
                myString = myString & vbCrLf & _
                    "List " & j & " contains " & _
                    .Lists(j).ListParagraphs.Count & _
                    " items:" & vbCrLf
                For i = 1 To .Lists(j).ListParagraphs.Count
                    myString = myString & _
                        .Lists(j).ListParagraphs(i).Range.Text
                Next
            Next
            MsgBox myString
        Else
            MsgBox "There are no lists in the document."
        End If
    End With
End Sub

--
Hope this helps,
Pesach Shelnitz
















- Show quoted text -

Oh ya... it did contain lists. The macros were usefull in detecting
them. But the list were present in a table plus it didnt have the word
"and" if the list had "and " in them it makes sense.

But when the table didnt have word and its showig comments, which
doesnt seem correct to me
Is it possible to create macros which can ignore lists if present in
a table.
 
S

Sahana

Oh ya... it did contain lists. The macros were usefull in detecting
them. But the list were present in a table plus it didnt have the word
"and" if the list had "and " in them it makes sense.

But when the table didnt have word and its showig comments, which
doesnt seem correct to me
 Is it possible to create macros which can ignore lists if present in
a table.- Hide quoted text -

- Show quoted text -

is it possible to help me in this?
 
P

Pesach Shelnitz

Hi Sahana,

The following version of the macro will skip lists in tables.

Sub conjunction()

Dim i As Long
Dim j As Long
Dim pos As Integer
Dim searchText As String
Dim myRange As Range

searchText = "and"
With ActiveDocument
For j = 1 To .Lists.Count
For i = 1 To .Lists(j).ListParagraphs.Count
Set myRange = .Lists(j).ListParagraphs(i).Range
With myRange
If .Information(wdWithInTable) = False Then
pos = InStrRev(myRange.Text, _
searchText, -1, vbTextCompare)
If pos > 0 And pos > Len(.Text) - 6 Then
.start = .start + pos - 1
.End = .start + Len(searchText)
.Select
Selection.Comments.Add _
Range:=Selection.Range, Text:= _
"Do not use ""and"" in a bullet list"
End If
End If
End With
Selection.Collapse Direction:=wdCollapseStart
Next
Next
End With
End Sub

Also, try changing the line in the previous version of the macro

If pos > Len(myRange.Text) - 6 Then

to

If pos > 0 And pos > Len(myRange.Text) - 6 Then

and see if this change makes it handle the lists within tables correctly.
 

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