Autorun Macro VBA on opening workbook

Copper Contributor

Hi there, 

 

I have a Macro for a scrolling marquee which works fine but I'm just trying to get it to run on opening the workbook. Any suggestions? No issue with the Macro, just activating autorun. 

 

Thanks.

 

Using this code: 

 

Private Sub Workbook_Open()
Sub DoMarquee()
Dim sMarquee As String
Dim iWidth As Integer
Dim iPosition As Integer
Dim rCell As Range
Dim iCurPos As Integer

'Set the message to be displayed in this cell
sMarquee = "Welcome. There is NEW information for you today."

'Set the cell width (how many characters you want displayed at once
iWidth = 50

'Which cell are we doing this in?
Set rCell = Sheet1.Range("M2")

'determine where we are now with the message.
' instr will return the position of the first
' character where the current cell value is in
' the marquee message
iCurPos = InStr(1, sMarquee, rCell.Value)

'If we are position 0, then there is no message, so start over
' otherwise, bump the message to the next characterusing mid
If iCurPos = 0 Then
'Start it over
rCell.Value = Mid(sMarquee, 1, iWidth)
Else
'bump it
rCell.Value = Mid(sMarquee, iCurPos + 1, iWidth)
End If

'Set excel up to run this thing again in a second or two or whatever
Application.OnTime Now + TimeValue("00:00:01"), "DoMarquee"
End Sub

1 Reply
Move the code starting from "Sub DoMarquee" up to the line starting with Application.OnTime to a normal module (From the menu: Insert, Module). Make sure both subs in both places have End Sub at their ends.