Animating a Menu Bar

J

Jan G. Thorstensen

Hi. I want to animate a menu bar that is floating in Excel and flies in from
left to right.

This is the code where I attemped to do it, but the screen isn't updated
properly.
How can I have a better visual look here. Thanks for helping.

CODE SNIPPET:
------------------



Sub MENU_Makro3()
Dim myBar As CommandBar
Dim i As Integer
'
Set myBar = CommandBars("My Menu")
With myBar
.Position = msoBarFloating
.Top = 245
' Wants to animate the menu bar flying in from Left
For i = 35 To 600
.Left = i
Next i
End With
' Unfortuneately you can hardly se the Menu Bar moving. Why is that???
End Sub


Regards
Jan
 
J

Jim Rech

This is better:

Sub MENU_Makro3()
Dim myBar As CommandBar
Dim i As Integer
Set myBar = CommandBars("My Menu")
With myBar
.Position = msoBarFloating
.Top = 245
DoEvents
For i = 35 To 600
.Left = i
DoEvents
Next i
End With
End Sub
 
J

jay

I think your menu is just not having enough time to redraw itself.
Play with the iPauseTime to adjust how fast the menu moves. I also
added a Step in your For..Next statement that can adjust the speed of
the animation.

Sub MENU_Makro3()
Dim myBar As CommandBar
Dim i As Integer
Dim iPauseTime
Dim iStart

iPauseTime = 0.01
Set myBar = CommandBars("My Menu")
With myBar
.Position = msoBarFloating
.Top = 245
' Wants to animate the menu bar flying in from Left

For i = 35 To 600 Step 4
iStart = Timer
Do While Timer < iStart + iPauseTime
DoEvents ' Yield to other processes.
Loop
.Left = i
Next i
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top