Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default changing the caption of a label

Hello all,

I created a userform with a label in Excel97 SR2. After the userform is
shown I want to change it's label through my code.
Below is the code I wrote, but the label doesn't display the string I
want it to display.

Dim MyString As String
MyString = "sample text"
UserForm1.Show
UserForm1.MyLabel.Caption = MyString

When the code that tells the form to appear is positioned at the end,
the label displays the right string. But this is not what I want, the
caption of the label must be changed multiple times.

thanks in advance,
Koos

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default changing the caption of a label

Koos,

In Excel97, all forms are what is called "Modeless". This means that no code
outside the form will run after the Show method until the form is hidden.
Therefore, the line 'UserForm1.MyLabel.Caption = MyString' doesn't execute
until you close the form.

Change the order of the lines, placing the Show method after changing the
caption. E.g.,

UserForm1.MyLabel.Caption = MyString
UserForm1.Show


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Koos" wrote in message
...
Hello all,

I created a userform with a label in Excel97 SR2. After the userform is
shown I want to change it's label through my code.
Below is the code I wrote, but the label doesn't display the string I
want it to display.

Dim MyString As String
MyString = "sample text"
UserForm1.Show
UserForm1.MyLabel.Caption = MyString

When the code that tells the form to appear is positioned at the end,
the label displays the right string. But this is not what I want, the
caption of the label must be changed multiple times.

thanks in advance,
Koos



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default changing the caption of a label

In XL97, all userforms are modal, which means that the macro code is
suspended once the userform is shown, until the form is closed.

You could use the userform's Initialize event (right-click the form,
choose View code, then select "Initialize" from the right-hand
dropdown) to set the label text, and you can change it in the event
code of any userform controls.

In article ,
Koos wrote:

Hello all,

I created a userform with a label in Excel97 SR2. After the userform is
shown I want to change it's label through my code.
Below is the code I wrote, but the label doesn't display the string I
want it to display.

Dim MyString As String
MyString = "sample text"
UserForm1.Show
UserForm1.MyLabel.Caption = MyString

When the code that tells the form to appear is positioned at the end,
the label displays the right string. But this is not what I want, the
caption of the label must be changed multiple times.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default changing the caption of a label

I already noticed that I can change the label's caption through some
code behind a commandbutton. Although that works fine, it is not the way
I want it to do.
What the problem really is, is that the label has to indicate the
progress of the calculations the excel-macro is doing. And I thought the
best way was to do that through text displayed on a label (and possibly
a progressbar). If there are any other possibilities to indicate this
progress I am interested in them. If these aren't available in excel 97
would it than be better to upgrade to a newer version?

thanks in advance,
Koos

J.E. McGimpsey wrote:
In XL97, all userforms are modal, which means that the macro code is
suspended once the userform is shown, until the form is closed.

You could use the userform's Initialize event (right-click the form,
choose View code, then select "Initialize" from the right-hand
dropdown) to set the label text, and you can change it in the event
code of any userform controls.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default changing the caption of a label

See John Walkenbach's tip for an example:
http://j-walk.com/ss/excel/tips/tip34.htm
Displaying a Progress Indicator

what version depends on who is going to use your application. If you
upgrade to xl2000 and your users are using xl97, this won't solve your
problem because those users are limited to xl97 capabilities (and in any
event you should always develop on the lowest version that will use the code
unless you are going to build separate apps for each version).

You seemed to miss the thrust of the advice given. Yes a commandbutton can
change the label, but so can code in the userform. With a modal userform,
you need to show the userform and then have any code run be run from the
userform. This is illustrated in John Walkenbach's tip above.

So, in the initialize event, as recommended, you initialize the value in the
userform label. Then you might have a button that starts the calculations
or otherwise start them - within the calculation code, you change the label
value or update the progress bar as shown by John.

You don't do

userform1.show
Calccode

because the Calccode is not executed until the userform is dropped. (hidden
or unloaded).

--
Regards,
Tom Ogilvy



Koos wrote in message
...
I already noticed that I can change the label's caption through some
code behind a commandbutton. Although that works fine, it is not the way
I want it to do.
What the problem really is, is that the label has to indicate the
progress of the calculations the excel-macro is doing. And I thought the
best way was to do that through text displayed on a label (and possibly
a progressbar). If there are any other possibilities to indicate this
progress I am interested in them. If these aren't available in excel 97
would it than be better to upgrade to a newer version?

thanks in advance,
Koos

J.E. McGimpsey wrote:
In XL97, all userforms are modal, which means that the macro code is
suspended once the userform is shown, until the form is closed.

You could use the userform's Initialize event (right-click the form,
choose View code, then select "Initialize" from the right-hand
dropdown) to set the label text, and you can change it in the event
code of any userform controls.






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
label caption gramps Excel Discussion (Misc queries) 0 November 1st 07 03:56 PM
Is it a comment ? or a label ? or a caption ?.... mars Excel Discussion (Misc queries) 2 May 24th 07 11:15 PM
Linking Cell to Label Caption papaitaliano Excel Worksheet Functions 1 March 21st 06 05:23 PM
label caption equal excel value Monique Excel Worksheet Functions 1 July 12th 05 07:33 PM
label caption Rod Taylor Excel Programming 2 July 31st 03 03:25 AM


All times are GMT +1. The time now is 09:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"