Macro running while form is loaded

Jshugs

New Member
Joined
Mar 24, 2009
Messages
23
I have a workbook with multiple buttons. Each button opens up a separate form. Also, I have a macro run in the background every minute or so using:
Code:
Application.OnTime
My problem is, when a form is visible and the macro runs in the background I get an error. So as a workaround I added a check to see if any forms were visible when the program in the background runs. If a form is visible then I exit the background program and try to run it again every 10 seconds or so until the form is no longer visible. I check to see if the forms are visible using
Code:
If FormName.Visible Then
RunWhen = Now + 10 / 86400
RunWhat = "AutoRun"
Application.OnTime EarliestTime:=RunWhen, Procedure:=RunWhat, Schedule:=True
Exit sub
End If

This kind of works, but it breaks down when another workbook is open and I'm not sure why. Any ideas? I would like to not use the work around if possible, but if anyone knows how to fix this, that would be great as well.

thanks!

-Jon
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
I have a workbook with multiple buttons. Each button opens up a separate form. Also, I have a macro run in the background every minute or so using:
Code:
Application.OnTime
My problem is, when a form is visible and the macro runs in the background I get an error. So as a workaround I added a check to see if any forms were visible when the program in the background runs. If a form is visible then I exit the background program and try to run it again every 10 seconds or so until the form is no longer visible. I check to see if the forms are visible using
Code:
If FormName.Visible Then
RunWhen = Now + 10 / 86400
RunWhat = "AutoRun"
Application.OnTime EarliestTime:=RunWhen, Procedure:=RunWhat, Schedule:=True
Exit sub
End If
This kind of works, but it breaks down when another workbook is open and I'm not sure why. Any ideas? I would like to not use the work around if possible, but if anyone knows how to fix this, that would be great as well.

thanks!

-Jon
If the forms are modal, try making them modeless. For example with UserForm1 use a statement like:
UserForm1.Show vbModeless
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top