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

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

DonkeyOte

MrExcel MVP
Joined
Sep 6, 2002
Messages
9,124
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

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
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

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
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

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,894
Office Version
  1. 365
Platform
  1. Windows
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,191,630
Messages
5,987,774
Members
440,109
Latest member
mitra2022

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
Top