Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Userform initializing problem when opening

I added the code below given by Tom in my folder but it doesn't really work.
The strange thing is that when I run the macro several times in a row with
the file open it works perfectly. But if I Close/Open Close/Open Close/Open,
each time I open it gives the same message. Any idea on how to change this?

By the way, is it possible to change the color of a msgbox?

Thank you.




"Tom Ogilvy" wrote:

Private Sub Userform_Initialize()

Dim rng as Range, i as Long
Set rng = Sheets("sheet2").Range("A1:A5")
i = Int(Rnd() * rng.Count + 1)
me.Label1.Caption = rng(i).Value

End Sub


this should be in the userform module.

--
Regards,
Tom Ogilvy


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Userform initializing problem when opening

If the data in Range("A1:A5") does not change, you will get the same result
every time.

You can change the color of the MsgBox in Control PanelAppearance and
ThemesDisplayappearanceAdvanced. When you change the color of the message
box, you also change the color of your window frames, i.e. Title bar and
Status bar.

"Cajeto 63" wrote:

I added the code below given by Tom in my folder but it doesn't really work.
The strange thing is that when I run the macro several times in a row with
the file open it works perfectly. But if I Close/Open Close/Open Close/Open,
each time I open it gives the same message. Any idea on how to change this?

By the way, is it possible to change the color of a msgbox?

Thank you.




"Tom Ogilvy" wrote:

Private Sub Userform_Initialize()

Dim rng as Range, i as Long
Set rng = Sheets("sheet2").Range("A1:A5")
i = Int(Rnd() * rng.Count + 1)
me.Label1.Caption = rng(i).Value

End Sub


this should be in the userform module.

--
Regards,
Tom Ogilvy


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Userform initializing problem when opening

Private Sub Userform_Initialize()

Dim rng as Range, i as Long
Randomize
Set rng = Sheets("sheet2").Range("A1:A5")
i = Int(Rnd() * rng.Count + 1)
me.Label1.Caption = rng(i).Value

End Sub

--
Regards,
Tom Ogilvy



"Cajeto 63" wrote in message
...
I added the code below given by Tom in my folder but it doesn't really
work.
The strange thing is that when I run the macro several times in a row with
the file open it works perfectly. But if I Close/Open Close/Open
Close/Open,
each time I open it gives the same message. Any idea on how to change
this?

By the way, is it possible to change the color of a msgbox?

Thank you.




"Tom Ogilvy" wrote:

Private Sub Userform_Initialize()

Dim rng as Range, i as Long
Set rng = Sheets("sheet2").Range("A1:A5")
i = Int(Rnd() * rng.Count + 1)
me.Label1.Caption = rng(i).Value

End Sub


this should be in the userform module.

--
Regards,
Tom Ogilvy




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Userform initializing problem when opening

Tom,
thank you for the randomize tip, it works very well now.

About the msgbox color, do you know if there is a way to have it change thru
VBA code and then set it back to normal after the msgbox has been clicked OK?

Or is JLGWhiz solution the only solution?

Thanks for your help.

"Tom Ogilvy" wrote:

Private Sub Userform_Initialize()

Dim rng as Range, i as Long
Randomize
Set rng = Sheets("sheet2").Range("A1:A5")
i = Int(Rnd() * rng.Count + 1)
me.Label1.Caption = rng(i).Value

End Sub

--
Regards,
Tom Ogilvy



"Cajeto 63" wrote in message
...
I added the code below given by Tom in my folder but it doesn't really
work.
The strange thing is that when I run the macro several times in a row with
the file open it works perfectly. But if I Close/Open Close/Open
Close/Open,
each time I open it gives the same message. Any idea on how to change
this?

By the way, is it possible to change the color of a msgbox?

Thank you.




"Tom Ogilvy" wrote:

Private Sub Userform_Initialize()

Dim rng as Range, i as Long
Set rng = Sheets("sheet2").Range("A1:A5")
i = Int(Rnd() * rng.Count + 1)
me.Label1.Caption = rng(i).Value

End Sub


this should be in the userform module.

--
Regards,
Tom Ogilvy





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Userform initializing problem when opening

I don't know of an easy way. Use a Userform instead and you can do it.

--
Regards,
Tom Ogilvy




"Cajeto 63" wrote:

Tom,
thank you for the randomize tip, it works very well now.

About the msgbox color, do you know if there is a way to have it change thru
VBA code and then set it back to normal after the msgbox has been clicked OK?

Or is JLGWhiz solution the only solution?

Thanks for your help.

"Tom Ogilvy" wrote:

Private Sub Userform_Initialize()

Dim rng as Range, i as Long
Randomize
Set rng = Sheets("sheet2").Range("A1:A5")
i = Int(Rnd() * rng.Count + 1)
me.Label1.Caption = rng(i).Value

End Sub

--
Regards,
Tom Ogilvy



"Cajeto 63" wrote in message
...
I added the code below given by Tom in my folder but it doesn't really
work.
The strange thing is that when I run the macro several times in a row with
the file open it works perfectly. But if I Close/Open Close/Open
Close/Open,
each time I open it gives the same message. Any idea on how to change
this?

By the way, is it possible to change the color of a msgbox?

Thank you.




"Tom Ogilvy" wrote:

Private Sub Userform_Initialize()

Dim rng as Range, i as Long
Set rng = Sheets("sheet2").Range("A1:A5")
i = Int(Rnd() * rng.Count + 1)
me.Label1.Caption = rng(i).Value

End Sub


this should be in the userform module.

--
Regards,
Tom Ogilvy




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
Initializing UserForm which uses MultiPage controls, part 2 Patrick Simonds Excel Programming 1 August 19th 06 11:06 PM
Initializing UserForm which uses MultiPage controls Patrick Simonds Excel Programming 6 August 15th 06 02:42 AM
stop userform from initializing JT[_2_] Excel Programming 3 March 4th 05 07:18 PM
Initializing Combobox in a Userform Neal[_5_] Excel Programming 2 September 15th 04 12:19 AM
Initializing Userform Szadkowski Excel Programming 1 August 31st 04 12:35 AM


All times are GMT +1. The time now is 04:19 PM.

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

About Us

"It's about Microsoft Excel"