Run macro in the background

bjanger

Board Regular
Joined
Jun 16, 2006
Messages
141
Hi,

I know there is a way to run macro in the background i.e. without seeing all steps in the macro being executed, but I can't remember the code.

Anyone who knows it?

BR
Bjanger
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
turn off screen updating property... however if using this option always a good idea to put an error handler into the routine such that were it to fail screenupdating would be reset to True !

Code:
Sub Marine()
On Error GoTo Handler:
Application.ScreenUpdating = False
....
Application.ScreenUpdating = True
Exit Sub

Handler:
Application.ScreenUpdating = True
Stop

End Sub
 
Upvote 0
Turning off screen updating doesn't strictly make the code execute in the background - the user interface is effectively disabled (or rather pretty much unusable) whilst the macro executes.

Application.ScreenUpdating is one of those settings that automatically resets to True on macro completion (so having error handling to reset it is not really necessary). The reason why you see it set to True in so many routines is to adhere to good coding practice.

The behaviour of Screenupdating resetting to True is in contrast to other settings (most notably EnableEvents, for example) that does not reset to True - so you should always use error handling if you turn off events (and want them back on again).
 
Upvote 0
Yes, it's wrong.

EDIT: perhaps when it was first released that may have applied to xl2002 but presumably subsequent patches have fixed that and it never applied to 2003 AFAIK.
 
Last edited:
Upvote 0
Application.ScreenUpdating is one of those settings that automatically resets to True on macro completion (so having error handling to reset it is not really necessary). The reason why you see it set to True in so many routines is to adhere to good coding practice.

Er, I remember you telling me this not so long ago, and since then I haven't bothered setting it back to True and I never ntoiced any adverse effects.

Jon
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,718
Members
448,986
Latest member
andreguerra

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