Making changes to button captions

K

Ken

If I have a form with a button then I can change the caption on the
button with the VBA code:

MyForm.Button1.Caption = "Text"

If I save and exit the document then the change is lost and the next
time I open the document I get the old caption.

Is there a way to make the changed caption stick?
 
G

Greg Maxey

Set the caption with VBA in the UserForm initialize event:

Private Sub UserForm_Initialize()
Me.CommandButton1.Caption = "Text"
End Sub
 
K

Ken

Doesn't do what I want. It changes the caption but if the document is
saved then re-opened, the old caption appears.

Effectively what I want to do is to change the default caption for the
button so that next time the document is opened the new caption
appears.
 
G

Graham Mayor

It works for me. Have you saved the userform and the macro in the document?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
K

Ken

The initialization routine changes the captions only for the duration
of the run.

What I have is a template that pops up a non modal form containing 20
buttons. Each button has as its caption the name of a macro and
clicking a button executes the code:
Application.Run.MacroName = myForm.Button1.caption

An editing project lasts about a week and for the following project it
is necessary to use different macros from a collection of about 100,
and perhaps include some new macros. What I have tried is to copy the
relevant macros into a module then run code at initialization that
gets a list of names of macros in the module and puts them into button
captions. However this does not work with an add-in template because
when a template is run it cannot access its own modules. But it does
work if the template document is open at the same time as the form is
being popped up.

What I would like to do is to be able to dump the required macros into
a module and run code that changes the captions then save the template
with new default captions. Otherwise it is necessary to manually
change the caption of each button.
 

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