Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
cdb
 
Posts: n/a
Default How can I run a macro in the background whilst a UserForm is visib

I have a workbook with an update button on (which has a macro behind it).
When I press this button I want a userform to open and display a flashing
message for the duration of the macro. I have tested all the bits seperately
and they all work fine - the update macro by itself works and updates the
data and the userform opens and display a flashing message if opened by
itself.

The problem I have is, if I put the userform into the update macro, once I
click the button the userform displays, but none of the code in the macro
works. I have tried adding the DoEvents code in but this doesn't seem to help.

Can anyone help me?

Code below:
-------------------------------------------------------------------------------------------------
Sub UpdateData()
DoEvents
UserForm1.Show
~ My Code
UserForm1.Hide
End Sub

------------------------------------------

Private Sub UserForm_Activate()
Label1.Visible = False
StartLoop:
If Label1.Visible = False Then Label1.Visible = True Else Label1.Visible =
False
RunPause
GoTo StartLoop
End Sub

------------------------------------------

Sub RunPause()
PauseTime = 0.75 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
End Sub

------------------------------------------

Private Sub UserForm_Terminate()
End
End Sub
  #2   Report Post  
Jim Rech
 
Posts: n/a
Default

Unless you make the form's ShowModel property false this is true:

UserForm1.Show
MsgBox "You won't see me until the form is unloaded/hidden"


--
Jim Rech
Excel MVP
"cdb" wrote in message
...
|I have a workbook with an update button on (which has a macro behind it).
| When I press this button I want a userform to open and display a flashing
| message for the duration of the macro. I have tested all the bits
seperately
| and they all work fine - the update macro by itself works and updates the
| data and the userform opens and display a flashing message if opened by
| itself.
|
| The problem I have is, if I put the userform into the update macro, once I
| click the button the userform displays, but none of the code in the macro
| works. I have tried adding the DoEvents code in but this doesn't seem to
help.
|
| Can anyone help me?
|
| Code below:
| -------------------------------------------------------------------------------------------------
| Sub UpdateData()
| DoEvents
| UserForm1.Show
| ~ My Code
| UserForm1.Hide
| End Sub
|
| ------------------------------------------
|
| Private Sub UserForm_Activate()
| Label1.Visible = False
| StartLoop:
| If Label1.Visible = False Then Label1.Visible = True Else Label1.Visible =
| False
| RunPause
| GoTo StartLoop
| End Sub
|
| ------------------------------------------
|
| Sub RunPause()
| PauseTime = 0.75 ' Set duration.
| Start = Timer ' Set start time.
| Do While Timer < Start + PauseTime
| DoEvents ' Yield to other processes.
| Loop
| End Sub
|
| ------------------------------------------
|
| Private Sub UserForm_Terminate()
| End
| End Sub


  #3   Report Post  
cdb
 
Posts: n/a
Default

Jim,

If I make it modeless will it run the rest of the code, or will it keep
looping through the code to make the label flash?

I think the problem I'm having is trying to run two lots of code at once
(one to update in the background which opens up other sheets and imports
data, and one to load up the user form and make the label flash.

Is there any other way of making the text flash without looping through some
code to make the lebel visible and hiding it??

"Jim Rech" wrote:

Unless you make the form's ShowModel property false this is true:

UserForm1.Show
MsgBox "You won't see me until the form is unloaded/hidden"


--
Jim Rech
Excel MVP
"cdb" wrote in message
...
|I have a workbook with an update button on (which has a macro behind it).
| When I press this button I want a userform to open and display a flashing
| message for the duration of the macro. I have tested all the bits
seperately
| and they all work fine - the update macro by itself works and updates the
| data and the userform opens and display a flashing message if opened by
| itself.
|
| The problem I have is, if I put the userform into the update macro, once I
| click the button the userform displays, but none of the code in the macro
| works. I have tried adding the DoEvents code in but this doesn't seem to
help.
|
| Can anyone help me?
|
| Code below:
| -------------------------------------------------------------------------------------------------
| Sub UpdateData()
| DoEvents
| UserForm1.Show
| ~ My Code
| UserForm1.Hide
| End Sub
|
| ------------------------------------------
|
| Private Sub UserForm_Activate()
| Label1.Visible = False
| StartLoop:
| If Label1.Visible = False Then Label1.Visible = True Else Label1.Visible =
| False
| RunPause
| GoTo StartLoop
| End Sub
|
| ------------------------------------------
|
| Sub RunPause()
| PauseTime = 0.75 ' Set duration.
| Start = Timer ' Set start time.
| Do While Timer < Start + PauseTime
| DoEvents ' Yield to other processes.
| Loop
| End Sub
|
| ------------------------------------------
|
| Private Sub UserForm_Terminate()
| End
| End Sub



  #4   Report Post  
Jim Rech
 
Posts: n/a
Default

I think the problem I'm having is trying to run two lots of code at once

Yes, you must bring them together probably in the Activate event.

--
Jim Rech
Excel MVP
"cdb" wrote in message
...
| Jim,
|
| If I make it modeless will it run the rest of the code, or will it keep
| looping through the code to make the label flash?
|
| I think the problem I'm having is trying to run two lots of code at once
| (one to update in the background which opens up other sheets and imports
| data, and one to load up the user form and make the label flash.
|
| Is there any other way of making the text flash without looping through
some
| code to make the lebel visible and hiding it??
|
| "Jim Rech" wrote:
|
| Unless you make the form's ShowModel property false this is true:
|
| UserForm1.Show
| MsgBox "You won't see me until the form is unloaded/hidden"
|
|
| --
| Jim Rech
| Excel MVP
| "cdb" wrote in message
| ...
| |I have a workbook with an update button on (which has a macro behind
it).
| | When I press this button I want a userform to open and display a
flashing
| | message for the duration of the macro. I have tested all the bits
| seperately
| | and they all work fine - the update macro by itself works and updates
the
| | data and the userform opens and display a flashing message if opened
by
| | itself.
| |
| | The problem I have is, if I put the userform into the update macro,
once I
| | click the button the userform displays, but none of the code in the
macro
| | works. I have tried adding the DoEvents code in but this doesn't seem
to
| help.
| |
| | Can anyone help me?
| |
| | Code below:
|
| -------------------------------------------------------------------------------------------------
| | Sub UpdateData()
| | DoEvents
| | UserForm1.Show
| | ~ My Code
| | UserForm1.Hide
| | End Sub
| |
| | ------------------------------------------
| |
| | Private Sub UserForm_Activate()
| | Label1.Visible = False
| | StartLoop:
| | If Label1.Visible = False Then Label1.Visible = True Else
Label1.Visible =
| | False
| | RunPause
| | GoTo StartLoop
| | End Sub
| |
| | ------------------------------------------
| |
| | Sub RunPause()
| | PauseTime = 0.75 ' Set duration.
| | Start = Timer ' Set start time.
| | Do While Timer < Start + PauseTime
| | DoEvents ' Yield to other processes.
| | Loop
| | End Sub
| |
| | ------------------------------------------
| |
| | Private Sub UserForm_Terminate()
| | End
| | End Sub
|
|
|


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
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 12:40 AM
Can't get simple macro to run Abi Excel Worksheet Functions 5 January 12th 05 07:37 PM
Macro and If Statement SATB Excel Discussion (Misc queries) 2 December 3rd 04 04:46 PM
Macro Formula revision? Mark Excel Worksheet Functions 1 November 28th 04 01:43 AM
Macro for multiple charts JS Excel Worksheet Functions 1 November 19th 04 03:44 AM


All times are GMT +1. The time now is 12:40 PM.

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"