PDA

View Full Version : Correcting gramatical errors



gmaxey
04-08-2014, 08:20 AM
If I type the following sentences:
I am a man.
She is a woman.
They are children.

And then intentionally alter them with the wrong verb, Word will flag the grammar errors "are, am, is"
I are a man.
She am a woman.
They is children.

Despite it's shortcomings, Word always lists the correct verb as the first item in the right click menu. I'm trying to come up with some code that will evaluate a personnel pronoun (e.g., I, She, He, it, etc.) and if the following word results in a grammatical subj-verb agreement error, then automatically replace that word with the first replacement option listed in the right click menu?


I'm beginning to think this is not possible, but thought I would throw it out and see if anyone else had ideas:


Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Range
Dim lngIndex As Long
For lngIndex = 1 To ActiveDocument.Range.Sentences.Count
Set oRng = ActiveDocument.Range.Sentences(lngIndex)
If oRng.GrammaticalErrors.Count > 0 Then
'Get really clunky here.
Select Case oRng.Words(1).Text
Case "I ", "She ", "They "
'Is the following word a flagged gramatical error?
'Is the error type a subj-verb agreement?
'Apply the first suggested correction.
End Select
End If
Next lngIndex
End Sub

macropod
04-08-2014, 03:23 PM
I'm trying to come up with some code that will evaluate a personnel pronoun
That's a new one! I've heard of personal pronouns before, but not a personnel pronoun :whip

gmaxey
04-08-2014, 05:38 PM
I'm a careless typist. You know that ;-)

macropod
04-08-2014, 08:29 PM
Whilst I agree it would be nice to be able to handle this programmatically, the problem I see is that what Word returns as the grammatical error isn't just the word it underlines in green and that you don't know where in the sentence the word it's out of synch with occurs. Your examples are fairly simple but wouldn't work if the sentence was "What do I do if they is children.", for example.

gmaxey
04-08-2014, 08:37 PM
Paul,

Right. That is why I was rapidly coming to t he conclusion that it isn't possible :-(

fumei
04-08-2014, 10:01 PM
I am not all that familiar with grammatical objects in Word. Can errors be pointed to specific points (either as numbers or word count) within a range?

gmaxey
04-09-2014, 05:43 AM
Gerry,

I don't think so. While you can get additional information about an error from the dialog, I don't see any way to get it via VBA.

snb
04-10-2014, 02:58 AM
Sub M_snb()
sn = Split("i is|i are|you am|you is|he am|he are|she am|she are|it am|it are|we am|we is|you am|you is|they am|they is", "|")
sp = Split("i am|i am|you are|you are|he is|he is|she is|she is|it is|it is|we are|we are|you are|you are|they are|they are", "|")

For j = 0 To UBound(sn)
AutoCorrect.Entries.Add sn(j), sp(j)
Next
End Sub

macropod
04-10-2014, 03:09 AM
Sub M_snb()
sn = Split("i is|i are|you am|you is|he am|he are|she am|she are|it am|it are|we am|we is|you am|you is|they am|they is", "|")
sp = Split("i am|i am|you are|you are|he is|he is|she is|she is|it is|it is|we are|we are|you are|you are|they are|they are", "|")

For j = 0 To UBound(sn)
AutoCorrect.Entries.Add sn(j), sp(j)
Next
End Sub
Another demonstration of your ability to code but not grasp the OP's needs or the consequences of what running your code will do. Aside from the fact you've omitted quite a few possibilities, you can't just blindly add these terms as auto-corrects and expect the right result. I, for one, would not want 'He and I are grammarians' being 'auto-correct'ed to 'He and i am grammarians'.

gmaxey
04-10-2014, 04:58 AM
Sub Tally
postcount = postcount+1
End Sub

fumei
04-10-2014, 08:46 AM
Another demonstration of your ability to code but not grasp the OP's needs or the consequences of what running your code will do. Aside from the fact you've omitted quite a few possibilities, you can't just blindly add these terms as auto-corrects and expect the right result. I, for one, would not want 'He and I are grammarians' being 'auto-correct'ed to 'He and i am grammarians'.
I do not think he gives a crap.

or "He and she are married" becoming "He and she is married"

macropod
04-10-2014, 02:36 PM
or "He and she are married" becoming "He and she is married"
Well, I suppose one might argue that one's at least theologically correct, if not grammatically so:
Genesis 2:24 Therefore a man leaves his father and his mother and cleaves to his wife, and they become one flesh.

fumei
04-10-2014, 10:50 PM
Or they ARE one flesh...to bring things into present tense, which is something a marriage should hang on to; especially when grammar does not do such a great job. I do have to comment that given a toss up between grammar versus theology, I will choose grammar, at least it has some level of rational sense.

macropod
04-11-2014, 01:45 AM
Maybe that's only because you don't really understand the latter...

fumei
04-11-2014, 02:30 PM
And maybe because I DO.

Theology is the systematic and rational study of concepts of God and of the nature of religious truths I studied under Jesuits from grade school through university. I have also studied Islam in Pakistan (I first read the Qua'rn when I was 10), and Buddhism and Hinduism in India. I think I can say that I have worked on the systematic and rational study of concepts of God and of the nature of religious truths.

fumei
04-11-2014, 03:43 PM
One could also argue that there is only a tenuous theological aspect of marriage, in that theology is the study of God, and marriage in all its weird and wonderful forms relates to (at best) the rules and tenets of religion . After all there can be marriage without ANY connection with religion...or God.