Form button question

B

Bri

hi

Is the Name of a form button the same as the Caption ON the button???
Unlike with command buttons from the control toolbox , I can't seem to see a
Properties window for form buttons. Where is it?

Thanks,
bri
 
K

Ken Johnson

Hi Bri,
The Name and captions are not the same.
Say you place a Forms button on a sheet, its automatic name is what
appears in the Name box on the right side of the Formula bar, eg Button
1.
The automatic caption is also Button 1.
The name can be changed by selecting the button with a right click,
clicking in the Name box, editing the name, then clicking Enter.
The caption can be changed by selecting the button with a right click,
selecting Edit text from the contextual menu, editing the text, then
clicking on the sheet.
In your code, if you need to return the caption on a button (say
button Name = Button 1) that is on the ActiveSheet, you can Dim a
String variable for storing the caption, Dim a Shape object, set the
Shape object to be the required button then reference as below..

Dim strCaption as String
Dim MyButton as Shape
Set MyButton = ActiveSheet.Shapes("Button 1")
strCaption = MyButton.TextFrame.Characters.Text

If you have a number of buttons on a sheet which all run the same macro
you might want to determine in your code which button the user pressed.
The name of that button is returned by Application.Caller eg...

If Application.Caller = "Button 1" then...


Ken Johnson
 
T

Tom Ogilvy

msgbox Activesheet.Buttons("Button 1").Caption

or

msgbox Activesheet.Buttons("Button 1").Name

Activesheets.buttons("Button 1").Caption = "ABC"

Dim Btn as Button
set btn = Activesheet.Buttons(application.Caller)
msgbox btn.name & " - " & btn.Caption

would be more direct and easier to use.
 
K

Ken Johnson

Hi Tom,
I was using the Object Browser as a guide. I guess a Forms button
equates to a CommandBar button, which has the caption property.

Thanks again Tom.

Ken Johnson
 

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