Toggle Options on & off 
Author Message
 Toggle Options on & off

I want to create a toolbar button to Toggle "Hide Spelling (&
gramatical) errors in this document".  I've created two simple macros:

Sub Off()
    With Options
        .CheckSpellingAsYouType = False
        .CheckGrammarAsYouType = False
    End With
End Sub

Sub On()
    With Options
        .CheckSpellingAsYouType = True
        .CheckGrammarAsYouType = True
    End With
End Sub

I assume I need to create a third toggle macro to check the state of
Spelling & Grammer True or false and then call the appropriate On or
Off macro.  If this is the right approach could anyone suggest how I
write the third macro.

Sandy



Mon, 20 Dec 2004 20:43:52 GMT  
 Toggle Options on & off
Hi Sandy,

The next piece of code toggles spelling checking on and of.

        With Options
        If .CheckSpellingAsYouType = True Then
        .CheckSpellingAsYouType = False
        ShowSpellingErrors = False
        Else
        .CheckSpellingAsYouType = True
        ShowSpellingErrors = True
        End If
        End With

But since you want to toggle both grammer and spelling checking, you
have a bit of a problem since there are four states for the two
options:
spelling / grammer
on / on
on / off
off / on
off / off

If you are absolutely sure that boith options are both on or both off,
it's easy,

In tha case you just add two lines to the above code:

        With Options
        If .CheckSpellingAsYouType = True Then
        .CheckSpellingAsYouType = False
       .CheckGrammarAsYouType = False
        ShowSpellingErrors = False
        Else
        .CheckSpellingAsYouType = True
       .CheckGrammarAsYouType = True
        ShowSpellingErrors = True
        End If
        End With

Maybe that is the best solution under all circumstances.
Check if spelling checking is on and on the basis of that change the
state of both options to the opposite of the status of spelling
checking.

Hope this helps,

Bart


Quote:
>I want to create a toolbar button to Toggle "Hide Spelling (&
>gramatical) errors in this document".  I've created two simple macros:

>Sub Off()
>    With Options
>        .CheckSpellingAsYouType = False
>        .CheckGrammarAsYouType = False
>    End With
>End Sub

>Sub On()
>    With Options
>        .CheckSpellingAsYouType = True
>        .CheckGrammarAsYouType = True
>    End With
>End Sub

>I assume I need to create a third toggle macro to check the state of
>Spelling & Grammer True or false and then call the appropriate On or
>Off macro.  If this is the right approach could anyone suggest how I
>write the third macro.

>Sandy



Mon, 20 Dec 2004 21:21:33 GMT  
 Toggle Options on & off
Many thanks Bart, perfect.  It seems obvious now you have
explained.

Yes, I always change Spelling and Grammar as a pair.  
Depending on the type of doc I'm working with checkers are
either very useful or just annoying.  Although looking
back at my posting I obviously had the spell checker off
gramArhhhh!

Thanks again,
Sandy

PS A bit presumptious to ask, but would you know how to
make one of those in(depressed)/out type toolbar buttons I
can attach to your macro that will visibly show me the
state of the checkers.

Quote:
>-----Original Message-----
>Hi Sandy,

>The next piece of code toggles spelling checking on and
of.

>        With Options
>        If .CheckSpellingAsYouType = True Then
>        .CheckSpellingAsYouType = False
>        ShowSpellingErrors = False
>        Else
>        .CheckSpellingAsYouType = True
>        ShowSpellingErrors = True
>        End If
>        End With

>But since you want to toggle both grammer and spelling
checking, you
>have a bit of a problem since there are four states for
the two
>options:
>spelling / grammer
>on / on
>on / off
>off / on
>off / off

>If you are absolutely sure that boith options are both on
or both off,
>it's easy,

>In tha case you just add two lines to the above code:

>        With Options
>        If .CheckSpellingAsYouType = True Then
>        .CheckSpellingAsYouType = False
>       .CheckGrammarAsYouType = False
>        ShowSpellingErrors = False
>        Else
>        .CheckSpellingAsYouType = True
>       .CheckGrammarAsYouType = True
>        ShowSpellingErrors = True
>        End If
>        End With

>Maybe that is the best solution under all circumstances.
>Check if spelling checking is on and on the basis of that
change the
>state of both options to the opposite of the status of
spelling
>checking.

>Hope this helps,

>Bart



>>I want to create a toolbar button to Toggle "Hide
Spelling (&
>>gramatical) errors in this document".  I've created two
simple macros:

>>Sub Off()
>>    With Options
>>        .CheckSpellingAsYouType = False
>>        .CheckGrammarAsYouType = False
>>    End With
>>End Sub

>>Sub On()
>>    With Options
>>        .CheckSpellingAsYouType = True
>>        .CheckGrammarAsYouType = True
>>    End With
>>End Sub

>>I assume I need to create a third toggle macro to check
the state of
>>Spelling & Grammer True or false and then call the
appropriate On or
>>Off macro.  If this is the right approach could anyone
suggest how I
>>write the third macro.

>>Sandy

>.



Tue, 21 Dec 2004 04:40:13 GMT  
 Toggle Options on & off
Hi Sandy,

This has been another learning experience for me too.
But I think I got it.
First you have to add a button for the macro to a toolbar. (It is
probably best to make a new toolbar for your own macro's and
functions.)
When that is done, you add the next lines to the macro

BarName = "MyBar"     ' Use the name of your toolbar
ButtonNr = 1            ' Assuming the first button on the bar

        Set c = CommandBars(BarName).Controls(ButtonNr)
        With c
        If Options.CheckSpellingAsYouType = True Then
        .State = msoButtonDown          ' SpellCheck = on
        Else
        .State = msoButtonUp            ' SpellCheck = off
        End If
        End With

Information about adding a toolbar and adding a button to a toolbar
you can find in the Word Help.
Good luck!

Bart



Quote:
>Many thanks Bart, perfect.  It seems obvious now you have
>explained.

>Yes, I always change Spelling and Grammar as a pair.  
>Depending on the type of doc I'm working with checkers are
>either very useful or just annoying.  Although looking
>back at my posting I obviously had the spell checker off –
>gramArhhhh!

>Thanks again,
>Sandy

>PS A bit presumptious to ask, but would you know how to
>make one of those in(depressed)/out type toolbar buttons I
>can attach to your macro that will visibly show me the
>state of the checkers.

>>-----Original Message-----
>>Hi Sandy,

>>The next piece of code toggles spelling checking on and
>of.

>>        With Options
>>        If .CheckSpellingAsYouType = True Then
>>        .CheckSpellingAsYouType = False
>>        ShowSpellingErrors = False
>>        Else
>>        .CheckSpellingAsYouType = True
>>        ShowSpellingErrors = True
>>        End If
>>        End With

>>But since you want to toggle both grammer and spelling
>checking, you
>>have a bit of a problem since there are four states for
>the two
>>options:
>>spelling / grammer
>>on / on
>>on / off
>>off / on
>>off / off

>>If you are absolutely sure that boith options are both on
>or both off,
>>it's easy,

>>In tha case you just add two lines to the above code:

>>        With Options
>>        If .CheckSpellingAsYouType = True Then
>>        .CheckSpellingAsYouType = False
>>       .CheckGrammarAsYouType = False
>>        ShowSpellingErrors = False
>>        Else
>>        .CheckSpellingAsYouType = True
>>       .CheckGrammarAsYouType = True
>>        ShowSpellingErrors = True
>>        End If
>>        End With

>>Maybe that is the best solution under all circumstances.
>>Check if spelling checking is on and on the basis of that
>change the
>>state of both options to the opposite of the status of
>spelling
>>checking.

>>Hope this helps,

>>Bart



>>>I want to create a toolbar button to Toggle "Hide
>Spelling (&
>>>gramatical) errors in this document".  I've created two
>simple macros:

>>>Sub Off()
>>>    With Options
>>>        .CheckSpellingAsYouType = False
>>>        .CheckGrammarAsYouType = False
>>>    End With
>>>End Sub

>>>Sub On()
>>>    With Options
>>>        .CheckSpellingAsYouType = True
>>>        .CheckGrammarAsYouType = True
>>>    End With
>>>End Sub

>>>I assume I need to create a third toggle macro to check
>the state of
>>>Spelling & Grammer True or false and then call the
>appropriate On or
>>>Off macro.  If this is the right approach could anyone
>suggest how I
>>>write the third macro.

>>>Sandy

>>.



Tue, 21 Dec 2004 18:15:46 GMT  
 Toggle Options on & off
You've done it again Bart and thanks. All in all a button
to do exactly what I want.  I swapped "true" with "false"
so that the button is depressed when checkers are off (not
logical but more intuitive).

Slight problem the code relies on the button always
being in the same place and will fail if customising
toolbars moves it.  I wonder if something similar would
work based on the ID of the custom menu button assuming it
remains unique and constant regardless of position.  

Small tip for anyone else saving the checker code.  After
experimenting make sure the checker options are set to
preferred default (on) before saving in normal.dot

Sandy

Quote:
>-----Original Message-----
>Hi Sandy,

>This has been another learning experience for me too.
>But I think I got it.
>First you have to add a button for the macro to a
toolbar. (It is
>probably best to make a new toolbar for your own macro's
and
>functions.)
>When that is done, you add the next lines to the macro

>BarName = "MyBar" ' Use the name of your toolbar
>ButtonNr = 1                ' Assuming the first button on the
bar

>        Set c = CommandBars(BarName).Controls(ButtonNr)
>        With c
>        If Options.CheckSpellingAsYouType = True Then
>        .State = msoButtonDown              ' SpellCheck = on
>        Else
>        .State = msoButtonUp                ' SpellCheck = off
>        End If
>        End With

>Information about adding a toolbar and adding a button to
a toolbar
>you can find in the Word Help.
>Good luck!

>Bart

>On Thu, 4 Jul 2002 13:40:13 -0700, "Sandy V"


- Show quoted text -

Quote:

>>Many thanks Bart, perfect.  It seems obvious now you
have
>>explained.

>>Yes, I always change Spelling and Grammar as a pair.  
>>Depending on the type of doc I'm working with checkers
are
>>either very useful or just annoying.  Although looking
>>back at my posting I obviously had the spell checker
off
>>gramArhhhh!

>>Thanks again,
>>Sandy

>>PS A bit presumptious to ask, but would you know how to
>>make one of those in(depressed)/out type toolbar buttons
I
>>can attach to your macro that will visibly show me the
>>state of the checkers.

>>>-----Original Message-----
>>>Hi Sandy,

>>>The next piece of code toggles spelling checking on and
>>of.

>>>        With Options
>>>        If .CheckSpellingAsYouType = True Then
>>>        .CheckSpellingAsYouType = False
>>>        ShowSpellingErrors = False
>>>        Else
>>>        .CheckSpellingAsYouType = True
>>>        ShowSpellingErrors = True
>>>        End If
>>>        End With

>>>But since you want to toggle both grammer and spelling
>>checking, you
>>>have a bit of a problem since there are four states for
>>the two
>>>options:
>>>spelling / grammer
>>>on / on
>>>on / off
>>>off / on
>>>off / off

>>>If you are absolutely sure that boith options are both
on
>>or both off,
>>>it's easy,

>>>In tha case you just add two lines to the above code:

>>>        With Options
>>>        If .CheckSpellingAsYouType = True Then
>>>        .CheckSpellingAsYouType = False
>>>       .CheckGrammarAsYouType = False
>>>        ShowSpellingErrors = False
>>>        Else
>>>        .CheckSpellingAsYouType = True
>>>       .CheckGrammarAsYouType = True
>>>        ShowSpellingErrors = True
>>>        End If
>>>        End With

>>>Maybe that is the best solution under all circumstances.
>>>Check if spelling checking is on and on the basis of
that
>>change the
>>>state of both options to the opposite of the status of
>>spelling
>>>checking.

>>>Hope this helps,

>>>Bart



Tue, 21 Dec 2004 22:59:24 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. New Off Doc option & Auto_Exec

2. turn all toggles in field off

3. tabstrip.....toggle on/off

4. Active Desktop Toggle on and Off

5. ? How to toggle caption bar on/off at runtime

6. Toggle ToolTips On/Off

7. URL parameter to toggle off group tree

8. Making radio (option) buttons toggle

9. reset Toggle btn in Option Grp when, Next Record

10. Urgent -Turn off Tools, Options, Edit/Find/Confirm on Startup

11. Turning Off Record Change Confirm Options in VB

12. Turning off toolbar options

 

 
Powered by phpBB® Forum Software