Log in

View Full Version : Spellcheck in Word Forms



johannfswart
09-02-2009, 05:40 AM
I produce Word forms (password protected) which I place on our company LAN and that are then used by other employees.

These forms often have large text fields which the user would like to run a spellcheck on, i.e. I, the creator of the form do not require this facility; it is the user of the form.

I have had a look at your code on your site, KB Article ID 388 "Spell check only forms fields on a protected document" and have the following question:

Are all the users required to first install this macro on their workstations to be able to use it, or can the code somehow be made part of the Word document so that anyone who opens this form (from the LAN) will be able to spellcheck its text fields?

lucas
09-02-2009, 09:41 AM
Or you can put it in a template file and put it in the startup directory to be used as an addin. It will then be available to any document that is opened.

fumei
09-02-2009, 03:48 PM
It should be a template in the first place if they are loading it from the LAN. In which case, simply have the procedure in the .DOT file.

johannfswart
09-03-2009, 12:11 AM
Wow guys, now you've lost me!
Are you saying that I should, instead of saving the form (which is 4 pages) as a *.doc, I should save it as a *.dot?
If yes, how do I write the code into the template? And by what means will the user know that the facility is available and how to use it?

fumei
09-03-2009, 09:58 AM
1. Yes. ANY repeatable use of a document structure should come from a .DOT file (a template). That is what they are for.

2. How do you write the code into the template? By...writing the code into a code module of the template.

3. How will the user know? By any number of ways. You could have a "Spell Check Form" clickable text ('Icon") on a toolbar. You could have it as a keyboard shortcut. You could have it as a menu item: Tools > SpellCheck Form.

johannfswart
09-04-2009, 01:00 AM
"...writing the code into a code module of the template."
Having saved the "document" as template, how does one access the "code module"? (Please keep in mind you're talking to a VB illiterate; I've recorded a few macros and have tweaked some existing macros, but that's about the total of my VB knowledge. Am I at the right forum?)

lucas
09-04-2009, 07:16 AM
If it's not 2007 you can add a menu item to the template:

Add menu item (http://slucas.virtualave.net/Wink/CustomMenuItem.htm)

johannfswart
09-07-2009, 06:54 AM
Lucas/Fumei,
Thanks for your assistance. I did manage to make it work upon exiting the text field. I initially went wrong by not saving the code as part of the template.
Just one question: Is it possible, when the message box appears with "Demo one field spell check" to have an option to "Check Now" or "Check Later"?
If not, no problem; it works super as is.
Thanks again.

lucas
09-07-2009, 07:55 AM
Is this the code you are using:
http://www.vbaexpress.com/kb/getarticle.php?kb_id=388

'This is the code to use if you want this to run on exit from the last field on
'the form/template.
' Thanks to MOS Master and fumei for their help with this one

Sub myTotalCheckSpelling()
Dim iCnt As Integer

With Application.ActiveDocument
'Unprotect if protected
If .ProtectionType <> wdNoProtection Then _
.Unprotect Password:=""

'Loop all formfields
For iCnt = 1 To .FormFields.Count
'Select formfield
.FormFields(iCnt).Select

#If VBA6 Then
'Only Word > 2000
Selection.NoProofing = False
#End If
'Set Language
Selection.LanguageID = wdEnglishUK
'Run spell checker
Selection.Range.CheckSpelling
Next

'Reprotect without resetting the fields
.Protect Type:=wdAllowOnlyFormFields, Noreset:=True, Password:=""

MsgBox "Demo all fields spell check completed", vbInformation
End With
End Sub


I think that they suggest using it on only the last form field in the document. That way it doesn't run on each one.

johannfswart
09-07-2009, 10:52 AM
No, I'm using the first part, i.e.

Option Explicit

Sub myCheckSpelling()
MsgBox "Demo one field spell check"

'Select Paragraph
ActiveDocument.Bookmarks("\Para").Select
With Selection
#If VBA6 Then
'Only Word > 2000
.NoProofing = False
#EndIf
'Set language
.LanguageID = wdEnglishUS
'Run spell checker
.Range.CheckSpelling
End With
End Sub


Edit Lucas: if you select your code when posting and hit the vba button then your code will be formatted for the forum...

lucas
09-07-2009, 11:33 AM
I only added the macro to the first 3 formfields on the attachment. Just to be sure that it does what you want. I had to zip it as I can't upload a .dot.

You will probably need to add the other macro(checks all fields) to the last formfield with a yes/no option too in case they did not check each one as they went.

Sub myCheckSpelling()
'MsgBox "Demo one field spell check"
Dim response As Integer
response = MsgBox("Check Now?", vbYesNo)
If response = vbYes Then
'Select Paragraph
ActiveDocument.Bookmarks("\Para").Select
With Selection
#If VBA6 Then
'Only Word > 2000
.NoProofing = False
#End If
'Set language
.LanguageID = wdEnglishUS
'Run spell checker
.Range.CheckSpelling
End With
Else: Exit Sub
End If
End Sub

johannfswart
09-07-2009, 11:18 PM
Hi Lucas, Thanks a million; this is exactly what I had in mind! It works like a charm. Many many thanks. :joy: :joy: :joy:

johannfswart
09-08-2009, 01:14 AM
Hi Lucas, apologies for being a pain.

I notice that the code at #9 above (i.e. the second part of

http://www.vbaexpress.com/kb/getarticle.php?kb_id=388)

which I have linked to the last field of the form, asks for a password.

Why is it necessary in this case? The user won't have the password.

lucas
09-08-2009, 06:20 AM
I don't see it asking for a password. Did you download the file from the kb and try it? It does not ask for a password.

Maybe you could post your document so we can see what is going on.

Make sure it doesn't have any personal or proprietary info in it before you upload it.

johannfswart
09-08-2009, 07:02 AM
The document password, as well as the form protection password is:

SEFRev1 -- upper and lower case as indicated.

lucas
09-08-2009, 09:29 AM
If you are using a password to protect the document then you need to put it in the code.


In the sub myTotalCheckSpelling

look for these lines and add your password as shown:

.Unprotect Password:=""

change to:

.Unprotect Password:="SEFRev1"


and

.Protect Type:=wdAllowOnlyFormFields, Noreset:=True, Password:=""

change to:

.Protect Type:=wdAllowOnlyFormFields, Noreset:=True, Password:="SEFRev1"

johannfswart
09-08-2009, 10:55 PM
"...and they all lived happily everafter."

Guys, thank you very much indeed! It now works just as intended.

I think this is a super site run by super people.

:hifive:
:beerchug:

johannfswart
09-09-2009, 03:13 AM
Hi Lucas,
I am experimenting with the option of initiating the spellcheckers via a menu item, instead of upon exiting a text field.
I have followed your "Add menu item" procedure (#7 above), and initially, all works well.
Yet, after having closed the document and then re-opening it, the menu item seems to have disappeared, in fact, it does appear on the menu bar for a millisecond, and then disappears. In order to make it "come back", I unprotect the document, select Tools, Customize, and, in the Save in dropdown, I select the current document. Only then does the menu item re-appear.
Being a protected document, this obviously will be a problem for the user.
Is there something more I should do to make this menu item available to the user?

lucas
09-09-2009, 08:03 AM
I'm guessing that the reason is that you are adding your menu to the clone created from the .dot file and not in the .dot file itself.

You have to open a blank word document and then go to file-open and browse for the .dot file to actually open the template itself.

see attached.

johannfswart
09-10-2009, 12:01 AM
Hi Lucas,
Regarding your first paragraph:
No, I did not perform the "add menu item" procedure on a clone, or on a new document based on the template (File, New, New from template). I "opened" the .dot file (File, Open, *.dot), using the password, then "unprotected" the form, again using the password, and then added the menu items. I then reprotected the document (using Tools, Protect Document), and saved the template.
Regarding your second paragraph:
I then, pretending to be a user, opened a new doument (Document1.doc) based on the template (i.e. File, New, New from template). The menu item did not show on the toolbar as I expected.
I added your Rev 3 to my templates location, and the result is basically the same: no "check spelling" menu items, not as a document and neither as a template (at least not until I have unprotected the form, open the Customize menu and and select the template name in the 'Save in' dropdown, which obviously isn't possible for the user).
Question:
From the user's point of view, should he immediately see the added menu items upon creating a new document based on the template (i.e. File, New, New from template)? Or do I have an unrealistic expectation?
If you give your Rev 3 to any of your colleagues, would they see and be able to make use of the added menu items without further ado?

lucas
09-10-2009, 07:27 AM
From the user's point of view, should he immediately see the added menu items upon creating a new document based on the template (i.e. File, New, New from template)? Or do I have an unrealistic expectation?

This is a completely realisitic expectation and I don't know why it's happening. It must have something to do with your network or networks in general that I don't understand where word is concerned.

Leave this for a day or two and there are several very sharp people who visit here that might have an idea. I will continue to try to figure it out myself. Sorry I wasn't able to help with this. It should be as easy as you think.......

johannfswart
09-17-2009, 12:56 AM
Hi Lucas,
You were right; time did heal this malady, but not in the way we expected. In fact, I can't tell you how it happened, but after a few days' "maturation", it actually works as originally expected, i.e. any user who opens the form (from the LAN) sees the menu item and it works as intended. I did not do anything other than making a few layout changes.
Generally, I hate it when things such as this happens because I have not learnt anything from it. But for now, I'm happy to have a working form.
Thanks again for all your trouble and effort; it's sincerely appreciated.

fumei
09-17-2009, 08:58 AM
Ah the wonders of time and the quirkiness of (I assume) Windows.

I wish I knew why that sort of thing happens, but there is no doubt it does. It is sort of like smacking the TV - for those of us old enough to remember doing such things - in order to get a better signal.

Give it a good shake and hope that makes it work.