Only A-z in range selection

R

rhamre

I have a macro that goes through documents and deletes spaces that were
accidently inserted in the middle of words.

How can i make it so that the range selection, that's a spelling error, can
only be alpha characters?
 
G

Greg Maxey

Would be interested in how your macro processes pairs like: "to" and "tally"
or "no" and "thing"

Does it treat the space as an accident and return "totally" and "nothing" or
does it leave them alone?
 
R

rhamre

The bulk of the spaces inserted created spelling errors.

The occurences that get past this macro are very rare, and that being the
case, in the thousands of files in which this problem exists, the space
that's insterted and creates 2 seperate real words is not a problem.

This macro only fixes words where one half or 1/3, of the word returns a
misspelling.
 
H

Helmut Weber

Hi Greg,
Would be interested in how your macro processes pairs like: "to" and "tally"
or "no" and "thing"

Does it treat the space as an accident and return "totally" and "nothing" or
does it leave them alone?

search for a-z space a-z.
Remember.
Delete the space.
Apply spelling check.
If spelling error, restore.

Like you, I wonder, whether that makes sense.

Could be.

Have a look at your mail inbox.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
G

Greg Maxey

I suppose that you could use the spelling error collection. Alphanumeric
combinations are ignore if the Option.IignoreMixedDigits is set to true:

Sub ScratchMacro()
Dim oSplErr As Range
Options.IgnoreMixedDigits = True
For Each oSplErr In ActiveDocument.SpellingErrors
MsgBox oSplErr
Next
End Sub
 
R

rhamre

Thanks for the reply Helmut.

Helmut Weber said:
search for a-z space a-z.
Remember.
Delete the space.
Apply spelling check.
If spelling error, restore.

Like you, I wonder, whether that makes sense.

The logic is good, and it works OK. The only problem with this one is if
greg's examples weren't 2 selections where the space was not accidently
inserted.

Now... statistically, the chances of 2 seperate words being able to join
each other and make a legitimate word, are higher than a space being randomly
inserted into 1 word to make 2 legitimate words.

And now, i wonder whether anything i just said makes sense

:)
 
R

rhamre

Greg Maxey said:
I suppose that you could use the spelling error collection. Alphanumeric
combinations are ignore if the Option.IignoreMixedDigits is set to true:

Sub ScratchMacro()
Dim oSplErr As Range
Options.IgnoreMixedDigits = True
For Each oSplErr In ActiveDocument.SpellingErrors
MsgBox oSplErr
Next
End Sub


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

Well, here's what my program does-

I have a loop for each spelling error in the document. Then, it finds the
space preceding the word and deletes it, then it checks to see if the newly
formed word is actually a word. Then, if that's not a word, it deletes the
space preceding that newly formed word, and if that's not a word, it goes
back to it's original spelling error. When that "Do while x = 1 to 2" i have
another to go for spaces proceeding the spelling error.

If it finds one it can fix, it highlights it a light grey, and then moves on
to the next spelling error.

Now, for this to work properly, i actually have to turn
Option.IgnoreMixedDigits to false. Here's why. I have a spelling error, it
deletes the space. Now, i have a set of numbers XXX and a spelling error, no
space seperating-

XXXSpellingerror If that option is set to true it doesnt recognize any
spelling error. I forsaw this and set up a check at the beginning of the
macro. If that option is set to true, it sets it to false and resets to true
at the end of the macro, if it's set to false, it doesnt do anything and
leaves it as false.

Here's why i need a check for non-letters. At the moment i'm doing a simple
"With Selection.Find" and i find [0-9\'\,\.\;], but, there could actually be
any number of non-alpha characters, and i would rather just have a check to
make sure the whole selection actually is alpha characters.

I hope all this makes sense.
 
G

Greg Maxey

Not sure I follow the whole concept, but if you want to validate a
spellingerror range (check it for numbers) then I suppose you could use
this:

Sub ScratchMacro()
Dim oSplErr As Range
Dim oChr As Range
Dim bValid As Boolean

For Each oSplErr In ActiveDocument.SpellingErrors
bValid = True
For Each oChr In oSplErr.Characters
If IsNumeric(oChr) Then
bValid = False
Exit For
End If
Next oChr
If bValid Then
MsgBox oSplErr 'Do your thing here
End If
Next oSplErr
End Sub


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


Greg Maxey said:
I suppose that you could use the spelling error collection.
Alphanumeric combinations are ignore if the
Option.IignoreMixedDigits is set to true:

Sub ScratchMacro()
Dim oSplErr As Range
Options.IgnoreMixedDigits = True
For Each oSplErr In ActiveDocument.SpellingErrors
MsgBox oSplErr
Next
End Sub


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

Well, here's what my program does-

I have a loop for each spelling error in the document. Then, it finds
the space preceding the word and deletes it, then it checks to see if
the newly formed word is actually a word. Then, if that's not a word,
it deletes the space preceding that newly formed word, and if that's
not a word, it goes back to it's original spelling error. When that
"Do while x = 1 to 2" i have another to go for spaces proceeding the
spelling error.

If it finds one it can fix, it highlights it a light grey, and then
moves on to the next spelling error.

Now, for this to work properly, i actually have to turn
Option.IgnoreMixedDigits to false. Here's why. I have a spelling
error, it deletes the space. Now, i have a set of numbers XXX and a
spelling error, no space seperating-

XXXSpellingerror If that option is set to true it doesnt recognize any
spelling error. I forsaw this and set up a check at the beginning of
the macro. If that option is set to true, it sets it to false and
resets to true at the end of the macro, if it's set to false, it
doesnt do anything and leaves it as false.

Here's why i need a check for non-letters. At the moment i'm doing a
simple "With Selection.Find" and i find [0-9\'\,\.\;], but, there
could actually be any number of non-alpha characters, and i would
rather just have a check to make sure the whole selection actually is
alpha characters.

I hope all this makes sense.
 

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