VBA not executing in proper order?

cr731

Well-known Member
Joined
Sep 17, 2010
Messages
611
I have a long-running macro and want to display a “Macro running… please wait” rectangle box. So, I created a box and then hid it. Here is my code (abbreviated for illustrative purposes):

Sheet1.Shapes(“Box”).Visisble = True
… other lines of code …
Sheet1.Shapes(“Box”).Visible = False

Strangely, running that macro does not result in first displaying the box, then running the code, then hiding the box. Instead, my code runs and then the box flashes and disappears in an instant. The total time for the macro is about 10 seconds… so I cannot understand why the box is not visible during that whole duration. How can my macro lines in between the show/hide be running before the box is shown?

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>Or am I missing something here?
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Stick DoEvents after each of those lines.
 
Upvote 0
Stick DoEvents after each of those lines.

After every line of my code? Or just after the lines of showing/hiding the box?

Changing my script to this makes no difference:

Sheet1.Shapes("Box_Hyperdownload").Visible = True
DoEvents

Application.Wait Now() + TimeValue("00:00:04")
DoEvents

Sheet1.Shapes("Box_Hyperdownload").Visible = False
DoEvents
(I added the wait command just to test)
 
Last edited:
Upvote 0
Or just after the lines of showing/hiding the box?
Yes, that.

Even so, if those lines are in a fast loop, you won't see much.
 
Upvote 0

Forum statistics

Threads
1,215,012
Messages
6,122,682
Members
449,091
Latest member
peppernaut

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