|
|
Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
I'm unfamiliar with the word object model- I do all my VBA in Excel, but I'm helping someone out with what should be a simple macro.
We are currently using [ActiveDocument.SpellingErrors.Count] which gives the count of all the misspelled words in the document. however, if the user is in the middle of typing a word (Inte when spelling Intelligent) then that counts as a misspelled word when that line of code executes. So, we'd like to adjust the range to count everything except the last word. Even better would be to include all words if the cursor is not "in" a word, e.g. the user types a space or a period or comma or anything that signifies that the last word is complete.
I'm thinking the simple version, always excluding the last word would be something like the following, but I don't know the syntax for Word well enough to make it work, or to conditionally include or exclude that last word.
Simple version (doesn't work):
myRng = ActiveDocument.SetRange(Start:=0, End:=ActiveDocument.words.count-1) ActiveDocument.myRng.SpellingErrors.Count
Thanks in advance for any help, Keith
|
|
KR was telling us: KR nous racontait que :
[Quoted Text] > I'm unfamiliar with the word object model- I do all my VBA in Excel, > but I'm helping someone out with what should be a simple macro. > > We are currently using [ActiveDocument.SpellingErrors.Count] which > gives the count of all the misspelled words in the document. however, > if the user is in the middle of typing a word (Inte when spelling > Intelligent) then that counts as a misspelled word when that line of > code executes. So, we'd like to adjust the range to count everything > except the last word. Even better would be to include all words if > the cursor is not "in" a word, e.g. the user types a space or a > period or comma or anything that signifies that the last word is > complete. > > I'm thinking the simple version, always excluding the last word would > be something like the following, but I don't know the syntax for Word > well enough to make it work, or to conditionally include or exclude > that last word. > > Simple version (doesn't work): > > myRng = ActiveDocument.SetRange(Start:=0, > End:=ActiveDocument.words.count-1) > ActiveDocument.myRng.SpellingErrors.Count
Dim rgeDoc As Range
Set rgeDoc = ActiveDocument.Range rgeDoc.MoveEnd wdWord, -2
("-2" because ¶ counts as words, so we have to remove the last ¶ from the range as well as the last word).
But what if the user is typing in the middle of the text, nit at the exact end? -- Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE[ at ]CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
|
|
Jean-Guy
Thank you for the code! It looks like I was going about it the wrong way :-)
[Quoted Text] > But what if the user is typing in the middle of the text, nit at the exact > end?
The task we are measuring is transcription, so hopefully we won't have that problem...unless the user happens to look up and see a spelling error, and is in the process of fixing it.
I suppose, for the sake of our data, that the best thing to do would be to capture the total character count of the document, and the current position (in characters) of the cursor. That way if the cursor isn't within a few characters of the end of the document, we'll know that they were somewhere else in the document, presumably fixing an error.
I know how to get the overall character count; what is the best way to determine the cursor's current location?
Thanks!! Keith
|
|
Hi KR,
in case Jean-Guy needs a break, ;-)
Sub test9002() Dim rDcm As Range Set rDcm = ActiveDocument.Range rDcm.End = selection.Range.End MsgBox "You are " & ActiveDocument.Characters.Count - 1 - _ rDcm.Characters.Count & " characters from the doc's end" End Sub
Note: You'll never reach the doc's end. You can't get beyond the last character.
-- Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003 "red.sys" & Chr$(64) & "t-online.de"
|
|
Helmut Weber was telling us: Helmut Weber nous racontait que :
[Quoted Text] > Hi KR, > > in case Jean-Guy needs a break, ;-)
Thanks!
It is July after all - and hot and sunny over here!
-- Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE[ at ]CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
|
|
Awesome- this is exactly what I needed! Thanks again, Keith
"Helmut Weber" <nbhymsjxdgcn[ at ]mailinator.com> wrote in message news:8vu4b2hsa3bgs906mmjti7kql5f869s486[ at ]4ax.com...
[Quoted Text] > Hi KR, > > in case Jean-Guy needs a break, ;-) > > Sub test9002() > Dim rDcm As Range > Set rDcm = ActiveDocument.Range > rDcm.End = selection.Range.End > MsgBox "You are " & ActiveDocument.Characters.Count - 1 - _ > rDcm.Characters.Count & " characters from the doc's end" > End Sub > > Note: You'll never reach the doc's end. > You can't get beyond the last character. > > -- > Greetings from Bavaria, Germany > > Helmut Weber, MVP WordVBA > > Win XP, Office 2003 > "red.sys" & Chr$(64) & "t-online.de"
|
|
|