Spelll check question, Word 2003, Windows XP

A

Alan Stancliff

In Word 2003, is there a way, with VBA code, to run a spell check on
just section 2 of a document?

I have been playing with various versions of ActiveDocument.sections(2),
but somehow, I don't quite seem to be able to figure it out.

Regards,

Alan Stancliff
 
G

Graham Mayor

You need something like:

Sub SpellSec2()
Dim Sec2 As Range
Set Sec2 = ActiveDocument.Sections(2).Range
With Sec2
.Select
#If VBA6 Then
.NoProofing = False
#End If
.LanguageID = wdEnglishUS
.CheckSpelling
End With
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

Alan Stancliff

Thanks Graham,

I'm still trying to learn the syntax for VBA.

I tried this little macro just now, and it skipped running a
spell-check on section 1 (good), spell-checked section 2 (good), but
also spell-checked section 3. Is there a way to keep it from checking
section 3?

Regards,

Alan Stancliff

*********
 
G

Graham Mayor

It only spell checks section 2 in my document?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

Alan Stancliff

That is odd, Graham. I will check it out again this evening after work.
Perhaps it was just a glitch. I'll get back to you and let you know. If
it still does not work for me, it may have something to do with the
third-party application I'm running with Word.

Regards,

Alan Stancliff
 
A

Alan Stancliff

Hi Graham,

It sure seems that it should work. It does skip spell checking section
one and does spell check section 2. But it also definitely spell checks
section 3, and I am not running any third-party applications just now as
I test it.

I wonder why that is?

Regards,

Alan Stancliff
 
G

Graham Mayor

The document I was using had no proofing set throughout. If the document has
the proofing option set then the spell check does appear to continue past
the end of second section. To overcome this, when all else fails hit it with
a blunt instrument ;)

Sub SpellSec2()
Dim rDoc As Range
Dim Sec2 As Range
Set rDoc = ActiveDocument.Range
With rDoc
.Select
#If VBA6 Then
.NoProofing = True
#End If
End With
Set Sec2 = ActiveDocument.Sections(2).Range
With Sec2
.Select
#If VBA6 Then
.NoProofing = False
#End If
.LanguageID = wdEnglishUS
.CheckSpelling
End With
End Sub

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

Alan Stancliff

Hi Graham,

Yup, that did it. Thanks.

I do have one other question though. You talk about hitting it with a
blunt object. Perhaps a bit more finesse is called for. Would you go for
a precision sledge hammer? I've been trying to get the boss to get me
one of those, along with a glass of hot chocolate, a bickie, and a
little mattress to roll out under my desk to take an afternoon nap when
it gets too frustrating.

Regards,

Alan Stancliff
 

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