slow down a macro?

Chavira55

Board Regular
Joined
Sep 19, 2002
Messages
65
is it possible to run a code in slow motion? I have a macro that reareanges the worksheet but I would like the macro to slow down.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

rikrak

Active Member
Joined
Aug 21, 2002
Messages
255
On 2002-10-18 15:54, Chavira55 wrote:
is it possible to run a code in slow motion? I have a macro that reareanges the worksheet but I would like the macro to slow down.

Hi,

Hit ALT+F8 to open the macro dialog.
Select the macro you want to run.
Select the Step-button.
The macro editor with the code shows up.
Hit F8 to step trough the code and see what each line of code does.

Hope this helps.
 

Asala42

Well-known Member
Joined
Feb 26, 2002
Messages
2,318
If you only want to slow down in a few places, you can sprinkle this line around in your code (to wait 2 seconds):

Application.Wait (Now + TimeValue("0:00:02"))
 

Chavira55

Board Regular
Joined
Sep 19, 2002
Messages
65

ADVERTISEMENT

Bugs, I have an arrow that "appears" pointing to certain key numbers on my sheet. This arrow (its a macro) goes thru the motions too fast so in the blink of an eye it is done traveling tru its path. If I can do it in slow motion, it would appear to slide thru the sheet to those points.
 
L

Legacy 98055

Guest
Chav.
You should post your code. Is this arrow moving in a loop?
Tom
 

Chavira55

Board Regular
Joined
Sep 19, 2002
Messages
65

ADVERTISEMENT

Here is the code that I have for the arrow (autoshape is the arrow)

Sub ARROW()
'
' ARROW Macro
' Macro recorded 10/18/2002 by Chavira55
'
ActiveSheet.Unprotect

ActiveSheet.Shapes("AutoShape 6").Select
Selection.ShapeRange.IncrementLeft 0.75
Selection.ShapeRange.IncrementTop 12.75
Selection.ShapeRange.IncrementLeft 0.75
Selection.ShapeRange.IncrementTop 21#
Selection.ShapeRange.IncrementLeft 23.25
Selection.ShapeRange.IncrementTop 33#
Selection.ShapeRange.IncrementLeft 42#
Selection.ShapeRange.IncrementTop 32.25
Selection.ShapeRange.IncrementRotation -26.17
Selection.ShapeRange.IncrementRotation -31.96
Selection.ShapeRange.IncrementLeft 24#
Selection.ShapeRange.IncrementTop -0.75
Selection.ShapeRange.IncrementLeft 36#
Selection.ShapeRange.IncrementTop 0.75
Selection.ShapeRange.IncrementLeft 70.5
Selection.ShapeRange.IncrementTop 4.5
Selection.ShapeRange.IncrementLeft 55.5
Selection.ShapeRange.IncrementTop -5.25
Selection.ShapeRange.IncrementLeft 60.75
Selection.ShapeRange.IncrementLeft 46.5
Selection.ShapeRange.IncrementTop -6#
Selection.ShapeRange.IncrementLeft 69.75
Selection.ShapeRange.IncrementTop 4.5
Selection.ShapeRange.IncrementTop 5.25
Selection.ShapeRange.IncrementRotation -0.21
Selection.ShapeRange.IncrementRotation 41.42
ActiveSheet.Shapes("AutoShape 6").Select
Selection.ShapeRange.IncrementRotation 41.14
Selection.ShapeRange.IncrementRotation 65.77
Selection.ShapeRange.IncrementRotation 22.01
Selection.ShapeRange.IncrementLeft -72#

End Sub
 
L

Legacy 98055

Guest
Play around with loops for much smoother display. If you are willing to stick with what you have currently, use the Sleep API function and place it strategically in your code at many and various points.
Partial example of your code:<pre>
Selection.ShapeRange.IncrementRotation -0.21: Sleep 5
Selection.ShapeRange.IncrementRotation 41.42: Sleep 5
Selection.ShapeRange.IncrementRotation 41.14: Sleep 5
Selection.ShapeRange.IncrementRotation 65.77: Sleep 5
Selection.ShapeRange.IncrementRotation 22.01: Sleep 5
Selection.ShapeRange.IncrementLeft -72#: Sleep 5</pre>


I recommend that you at least try out the
following and with a bit of a look this
method will be easy to use.<pre>
Option Explicit
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub asdf()
Dim l As Long, t As Long, HoldTop As Double
With Sheet1.Shapes("AutoShape 6")
.Left = 0
.Top = 0
Do Until .Top > 400
Sleep 5
DoEvents
.IncrementLeft 0.5
.IncrementTop 0.5
If .Top > 200 And .Top< 291 Then
.IncrementRotation -1
End If
Loop

Do
HoldTop = .Top
Sleep 5
DoEvents
.IncrementLeft -0.5
.IncrementTop -0.5
If .Top > 200 And .Top< 291 Then
.IncrementRotation -1
End If
Loop While HoldTop<> .Top

End With
End Sub</pre>

Tom
This message was edited by TsTom on 2002-10-19 00:50
 

Richie(UK)

MrExcel MVP
Joined
May 17, 2002
Messages
3,329
Hi Chavira55,

The "Option Explicit" statement goes at the very start of the module, so it will go before your arrow code.

It's purpose is to force the programmer to explicitly declare the variables used in the module. Quote from the VBE Help files:

Used at module level to force explicit declaration of all variables in that module.

Syntax

Option Explicit

Remarks

If used, the Option Explicit statement must appear in a module before any procedures.

When Option Explicit appears in a module, you must explicitly declare all variables using the Dim, Private, Public
, ReDim, or Static statements. If you attempt to use an undeclared variable name, an error occurs at compile time.

If you don't use the Option Explicit statement, all undeclared variables are of Variant type unless the default type is otherwise specified with a Deftype statement.

Note Use Option Explicit to avoid incorrectly typing the name of an existing variable or to avoid confusion in code where the scope of the variable is not clear.


In Tom's example routine it results in the following line being added by the programmer:

Dim l As Long, t As Long, HoldTop As Double

Without it, the variables (l,t, and HoldTop) would be assumed by Excel to be Variant data types rather than those specified. Variants should, in general, be avoided if possible as they take up more memory.

HTH

PS To force yourself to use "Option Explicit", go to Tools / Options in the VBE and select the "Require Variable Declaration" box. The VBE will then automatically add the line to the start of your modules.
 

Forum statistics

Threads
1,144,510
Messages
5,724,782
Members
422,578
Latest member
annsalinas

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