Code not working

J

Jennie

I created a new macro by copying code from another MVP
site...http://www.mvps.org/word/FAQs/MacrosVBA/SpellcheckP
rotectDoc.htm
The directions say to paste in between your macro name,

Sub SpellCheckProtect
and
End Sub

*but by doing this I contine to get errors
ie, Compile Error: Invalid inside procedure

*or If I put code after Sub and End Sub
ie Compile error: Only comments may appear after End
Sub...

*If I don't put my name and just use code given it will
only run 1st Sub Routine (Sub RunSpellcheck())

Please help, I must get this fixed before end-of-day
deadline
Thanks
 
K

Klaus Linke

Hi Jennie,

The lines

Option Explicit

Dim Cancelled As Boolean, MyRange As Range, _
CorrectedError As String, oDoc As Document

should appear at the very beginning of the module, above any Subs, since
they are declarations.

If you hit Ctrl+Home in the VBA editor, you'll go to the first line of the
module.
In case you see "Option Explicit" there already, you won't have to add it.

"Option Explicit" only tells VBA that you have to dimension all variables
explicitly (else you will get error messages).
"Dim Cancelled" dimensions a global variable "Cancelled", which can be used
by all macros in the module.

The Subs that follow can appear anywhere in the module.

The directions say to paste in between your macro name,

Sub SpellCheckProtect
and
End Sub

These directions are only for the case that the posted code doesn't already
have "Sub XXX() ... End Sub".
In this case, they are already are there, so you don't need to type
anything.

If you can't get it to work, download the Zip file from the end of the
article.
It contains all the code in a *.dot file.

Regards,
Klaus
 
J

Jay Freedman

Hi, Jennie,

The instructions say, "paste the following code in, first deleting anything
in the code module that Microsoft inserted automatically". That means you
should *delete* the two lines

Sub SpellCheckProtect

and

End Sub

and paste in the code from the web page *instead* of those lines, not
between them.

The first routine, RunSpellcheck, is the only one that you should run. The
other subroutines, which start with "Private", are used by the first one --
this happens on lines of code that start with the word Call.
 

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