Toggle Settings

A

AA

I'd like to be able to toggle some settings, for example "Windows in
TaskBar" or "View Text Boundaries".

Currently I have two macros to do this sort of thing, one for off and
one for on, and either two toolbar buttons or two shortcut keys to
activate the pairs of macros.

Is there a way to test for a setting? For example, to show text
boundaries, I use

ActiveWindow.View.ShowTextBoundaries = True

How would I test for whether they are on or off, so I could do the
appropriate If/Then and set up a toggle?

TIA,

Andy
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < AA > écrivait :
In this message, < AA > wrote:

|| I'd like to be able to toggle some settings, for example "Windows in
|| TaskBar" or "View Text Boundaries".
||
|| Currently I have two macros to do this sort of thing, one for off and
|| one for on, and either two toolbar buttons or two shortcut keys to
|| activate the pairs of macros.
||
|| Is there a way to test for a setting? For example, to show text
|| boundaries, I use
||
|| ActiveWindow.View.ShowTextBoundaries = True
||
|| How would I test for whether they are on or off, so I could do the
|| appropriate If/Then and set up a toggle?
||

All you need is one macro (and one button) with something like

With ActiveWindow.View
.ShowTextBoundaries = Not .ShowTextBoundaries
End With

If you want to get fancy, you can even change the look of the button every
time it is clicked on with something like

'_______________________________________
Dim Cbar As CommandBar
Dim MyButton As CommandBarButton

With ActiveWindow.View
.ShowTextBoundaries = Not .ShowTextBoundaries
End With

Set Cbar = CommandBars("TestBar")
With Cbar
Set MyButton = .Controls(1)
With MyButton
If ActiveWindow.View.ShowTextBoundaries Then
.State = msoButtonDown
Else
.State = msoButtonUp
End If
End With
End With
'_______________________________________

You will need a toolbar called "TestBar" on which the first button is the
one calling the toggling macro.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
A

AA

All you need is one macro (and one button) with something like

With ActiveWindow.View
.ShowTextBoundaries = Not .ShowTextBoundaries
End With

Sweet!

Any reason not to just make it one line (it is on one line, even if it formats differently
in this post)? This seems to work ok:

ActiveWindow.View.ShowTextBoundaries = Not ActiveWindow.View.ShowTextBoundaries

Is there an advantage to With,End With?

If you want to get fancy, you can even change the look of the button every
time it is clicked on with something like......

Oh that's exactly the sort of thing I'd waste a few hours playing with, probably when I
have work I really have to do. I'd love to have changing buttons.

Another time.

Merci Jean-Guy!!!

Andy
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < AA > écrivait :
In this message, < AA > wrote:

||| All you need is one macro (and one button) with something like
|||
||| With ActiveWindow.View
||| .ShowTextBoundaries = Not .ShowTextBoundaries
||| End With
||
|| Sweet!
||
|| Any reason not to just make it one line (it is on one line, even if it
formats differently
|| in this post)? This seems to work ok:
||
|| ActiveWindow.View.ShowTextBoundaries = Not
ActiveWindow.View.ShowTextBoundaries
||
|| Is there an advantage to With,End With?

I have not trained in programming, but I remember someone explaining that
every time you add a dot in the code, this creates a new reference in the
memory. So, to be on the safe side and to avoid cluttering up the memory
(And help the code run faster, I think) I try to use "With ... End With"
whenever it will save me a few dots, also, it makes the code easier to read
as it is not as cluttered with repeated object.

||
||
||| If you want to get fancy, you can even change the look of the button
every
||| time it is clicked on with something like......
||
|| Oh that's exactly the sort of thing I'd waste a few hours playing with,
probably when I
|| have work I really have to do. I'd love to have changing buttons.

You could easily adapt the code I posted in a few minutes...

||
|| Another time.
||
|| Merci Jean-Guy!!!

De rien!
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
A

AA

if you want to get fancy, you can even change the look of the
button every time it is clicked on with something like ....
You will need a toolbar called "TestBar" on which the first button
is the one calling the toggling macro.

Ah, the separate toolbar is the rub. Right now I have the button
right in the middle of my regular toolbar, so I would have to move it
off to one side.
I have not trained in programming, but I remember someone
explaining that every time you add a dot in the code, this creates
a new reference in the memory. So, to be on the safe side and to
avoid cluttering up the memory (And help the code run faster, I
think) I try to use "With ... End With" whenever it will save me a
few dots, also, it makes the code easier to read as it is not as
cluttered with repeated object.

Interesting.

Thanks,

Andy
 

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