Button Toggle?

A

Angyl

I use Word 2003 in the office and my boss (oddly enough) is stuck with 2000

I've created several custom forms for him to use and usually they're locked,
but on occasion he needs to unlock them to make minor adjustments.

Problem is, when he RE locks a form with the standard toolbar button,
everything he's entered in the fields goes away.

My solution will be to make him a new button/macro that will use the code:

ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

What I don't know how to do is make it a TOGGLE code like the default button
so that when you press it it either locks, or unlocks depending on whether
the document is currently locked or unlocked.

I could, of course just make him TWO buttons, one to lock and one to unlock,
but that isn't very sophisticated, is it?

Thanks for your help!
 
G

Greg Maxey

Angyl,

It can be done, but in my opinion it is brutally complicated and not worth
the effort. There is an example of an interactive toolbar in MyBookmarker
template that you can download here:

http://gregmaxey.mvps.org/Bookmark_Tool.htm

The problem is that changes in the toolbars can result in changes in the
template that can thne trigger the such and such template has been changed
do you want to save, blah, blah.
I could, of course just make him TWO buttons, one to lock and one to
unlock, but that isn't very sophisticated, is it?

No, but then a Colt .45 M1911-A1 isn't very sophisticated next to a Beretta
9mm, but it still blows and nasty hole in anything interfering with its
trajectory ;-)

Good luck
 
G

Greg Maxey

I don't have Word 2000 here. I thought the toolbar changed from a locked
padlock to an open padlock, but that isn't the case in Word 2003. You might
try intercepting the built-in command with:

Sub ProtectForm()
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect
Else
ActiveDocument.Protect wdAllowOnlyFormFields, NoReset:=True
End If
End Sub
 
J

Jean-Guy Marcil

Angyl was telling us:
Angyl nous racontait que :
I use Word 2003 in the office and my boss (oddly enough) is stuck
with 2000

I've created several custom forms for him to use and usually they're
locked, but on occasion he needs to unlock them to make minor
adjustments.

Problem is, when he RE locks a form with the standard toolbar button,
everything he's entered in the fields goes away.

My solution will be to make him a new button/macro that will use the
code:

ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

What I don't know how to do is make it a TOGGLE code like the default
button so that when you press it it either locks, or unlocks
depending on whether the document is currently locked or unlocked.

I could, of course just make him TWO buttons, one to lock and one to
unlock, but that isn't very sophisticated, is it?

Thanks for your help!

Try this with a toolbar named "TestBar" stored in the active document, the
"lock" button is the first button on that toolbar. You could put it
anywhere, then you would need to change the CommandBars line to get to the
button:

'_______________________________________
Sub myLockToggle()

CustomizationContext = ActiveDocument

With ActiveDocument
If .ProtectionType = wdNoProtection Then
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
.CommandBars("TestBar").Controls(1).State = msoButtonDown
Else
.Unprotect
.CommandBars("TestBar").Controls(1).State = msoButtonUp
End If
End With

End Sub
'_______________________________________

Of course, if the toolbar is in a template, as it probably is, change the
CustomizationContext line accordingly.

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

Greg Maxey

Yeah that look nice. You could also add a caption:

Sub myLockToggle()
CustomizationContext = ActiveDocument
With ActiveDocument
If .ProtectionType = wdNoProtection Then
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
With .CommandBars("TestBar").Controls(1)
.State = msoButtonDown
.Caption = "Unlock"
End With
Else
.Unprotect
With .CommandBars("TestBar").Controls(1)
.State = msoButtonUp
.Caption = "Lock"
End With
End If
End With
End Sub
 
G

Greg Maxey

And a changing button face. Padlock for "Lock" and "Broken Link" for
"Unlock" ;-)

Note 2309 is the msoControlButton ID for the broken chain icon
225 is the ID for the padlock. This could be different in Word 2000.

Sub myLockToggle()
CustomizationContext = ActiveDocument
Dim imgSource As Office.CommandBarButton
With ActiveDocument
If .ProtectionType = wdNoProtection Then
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
Set imgSource = CommandBars.FindControl(msoControlButton, 2309)
imgSource.CopyFace
With .CommandBars("TestBar").Controls(1)
.State = msoButtonDown
.Caption = "Unlock"
.PasteFace
End With
Else
.Unprotect
Set imgSource = CommandBars.FindControl(msoControlButton, 225)
imgSource.CopyFace
With .CommandBars("TestBar").Controls(1)
.State = msoButtonUp
.Caption = "Lock"
.PasteFace
End With
End If
End With
End Sub
 
J

Jean-Guy Marcil

Greg Maxey was telling us:
Greg Maxey nous racontait que :
And a changing button face. Padlock for "Lock" and "Broken Link" for
"Unlock" ;-)

Note 2309 is the msoControlButton ID for the broken chain icon
225 is the ID for the padlock. This could be different in Word 2000.

Sub myLockToggle()
CustomizationContext = ActiveDocument
Dim imgSource As Office.CommandBarButton
With ActiveDocument
If .ProtectionType = wdNoProtection Then
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
Set imgSource = CommandBars.FindControl(msoControlButton, 2309)
imgSource.CopyFace
With .CommandBars("TestBar").Controls(1)
.State = msoButtonDown
.Caption = "Unlock"
.PasteFace
End With
Else
.Unprotect
Set imgSource = CommandBars.FindControl(msoControlButton, 225)
imgSource.CopyFace
With .CommandBars("TestBar").Controls(1)
.State = msoButtonUp
.Caption = "Lock"
.PasteFace
End With
End If
End With
End Sub

Very nice, but personally I would try to keep my custom GUI in line with the
default one.

To that end, since the button is not created dynamically, I would manually
copy the padlock icon from the formfield toolbar and then display my button
with only the icon. I think I would even replace the button from the
formfield toolbar with my own, so users would not even know that I had
changed something and for them everything would be normal.

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

Greg Maxey

JGM,

Something tells me you probably wouldn't dance naked on table with a
lampshade on your head. ;-)
 
J

Jean-Guy Marcil

Greg Maxey was telling us:
Greg Maxey nous racontait que :
JGM,

Something tells me you probably wouldn't dance naked on table with a
lampshade on your head. ;-)

It depends who was feeding me the drinks....

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

Angyl

Do the two of you want to be left alone?

LOL!!

You seem to be enjoying yourselves with this. Thanks for all the advice,
I'll run through it and try to get this done!
 

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