Problem with command button name

J

Jason

Hi,

I am having a strange problem.
I have a workbook with 20 or so sheet, and on each sheet is a command
button. I have changed the default name of most of the command buttons to
better reflect its purpose, but a couple of them have been giving me
trouble.
I can change the name, and it stays that way while I have the workbook
open. But once I save the workbook, close it and then reopen it, the name
that I entered has reverted back to the default "CommandButton1". Any idea
what is going on here?

Thanks
 
D

Dave Peterson

And you're positive that you've saved the workbook?

And you're positive that you're opening the workbook that you saved?

One test if you're positive...
Open the workbook
make the changes
save the workbook
close excel

Open excel in safe mode
windows start button|run
excel /safe
file|open your workbook that was just saved

Are the commandbuttons renamed?

If no, then maybe you have a macro that's changing the names of your
commandbuttons each time you open that workbook???

If yes, I don't have a guess.
 
J

Jason

Hi Dave,

I have actually just noticed that while in Design Mode in the Properties
window the name has been changed, but in the name box it still says
CommandButton1. It's like it not properly changing the name at all!?

Also, how do you check the name of command buttons while in safe mode?
My Developer tab disappeared, and I am not able to re-add it in safe mode,
as well now, none of the names for the command buttons appear in the
name box.
 
J

Jason

Hmmm, is there a limit on the amount of character one can use for a
command button name? I have just noticed that all the buttons I am having
problems renaming would have names that are a little bit longer than the
buttons where renaming has worked.

3 buttons not allowing rename:
1st name is 35 chars long
2nd name is 33 chars long
3rd name is 36 chars long

Almost all the other names are under 30 chars long.
 
J

Jason

Turns out my problem was that the descriptive names I had chosen for the
Command Buttons were too long. 32 characters seems to be the limit.

Thank you Dave for your suggestion.
 
G

Gord Dibben

Jason

With button from Control Toolbox or Forms Toolbar I can get way more than 32
characters to appear after save/close and re-open.


Gord Dibben MS Excel MVP
 
J

Jason

Gord

It seemed like a pretty low number to me, but once I reduced the names to
32 chars or less, all my problematic buttons started to work right. What
can I say? Wierd.
Any thoughts why this might be the case?
 
D

Dave Peterson

I got 31 in this (only the commandbutton on the worksheet):

Option Explicit
Private Sub CommandButton1_Click()
With Me.OLEObjects(1)
Debug.Print .Name
.Name = String(32, "a")
Debug.Print .Name & "--" & Len(.Name)
End With
End Sub

CommandButton1
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa--31

Even though I tried to use 32 characters, it was truncated.

And if I changed it to:
..Name = String(33, "a")
I got a run time error.
 
G

George Nicholson

This is all a guess:

You may be able to give a command button a name longer that 32 characters,
but my guess is that the 1st 32 are all that matters. It may be that those
32 characters have to be unique among all command buttons names (maybe among
all control/shape/object names) and any additional characters are
essentially ignored.

If the first 32 characters of a name are not unique the name will not be
accepted and will not 'stick'.
 

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

Similar Threads


Top