Change Label1.Caption

S

Soniya

Hi,

Is it possible to change label1.caption in my userform at run time and
save it without saving the workbook.

When I cahned the caption at run time and then closed the userform and
rerun the code again the caption again changes to the default.

Thanks
 
J

Jim Thomlinson

You can not do what you are describing without storing the new value of the
caption somewhere. You can store it either in a cell somewhere, or in an INI
file (cell would be by far the easiest). When you initialize the form have
the label caption read from the cell.
 
S

Soniya

I am changing label1.caption by clicking commandbutton1.

I know code can be changed by using VBAProject.VBComponents.

but I could not get it to work in my case.

thanks
 
J

Jim Thomlinson

VBcomponents is a whole pile more difficult than this needs to be. Add a
sheet and call it "Form Variables" or something like that... Now in the form
initialization add something like...

label1.caption = sheets("Form Variables").Range("A1").Value

For your button add
label1.caption = "MySting"
sheets("Form Variables").Range("A1").Value = "MySting"

Now the value of the label caption is stored in the sheet and it is
initialized at run time. if you don't want your users getting at the value
make the sheet very hidden
sheets("Form Variables").visible = xlVeryhidden
 
B

Bob Phillips

Soniya,

You can change form attributes using Designer, but not from within the form
itself, you have to do it from outside when the form is inactive.

It hardly seems worth the effort. Jim's idea of storing the value somewhere
when you change it at runtime, and reading that on the next form initialize
is a whole heap simpler.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 

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