Share via

Userform that Closes Automatically

Anonymous
2013-03-06T16:15:24+00:00

Hello:

I came across this code and would like to try it, but I get a Compile Error:  User-defined type not defined on the second line of the code which reads Dim WithEvents CountdownTimer as TMTimer.clsTimer.  This code is suppose to work like a splash screen with a countdown timer that lets the user know when the form will shut down.  Thank you for your help!

Option Explicit
Dim WithEvents CountdownTimer As TMTimer.clsTimer

Private Sub CountdownTimer_CountdownComplete()
    Unload Me
    End Sub
Private Sub CountdownTimer_TimerTick(TimerVal As Single)
    Me.Label1.Caption = "This form will close in " _
        & Round(CountdownTimer.CurrentMilliSecsLeft / 1000, 0) & " seconds"
    End Sub
Private Sub startCounter()
    Set CountdownTimer = TMTimer.createTimer
    With CountdownTimer
    .CountdownDurationMilliSecs = 10 * 1000
    .TickIntervalMilliSecs = 3 * 1000
    .TimerType = .TimerTypeCountdown
    .startTimer
        End With
    End Sub

Private Sub Cancel_Click()
    CountdownTimer.cancelTimer
    Unload Me
    End Sub
Private Sub OK_Click()
    MsgBox "OK"
    CountdownTimer.cancelTimer
    Me.Hide
    End Sub
Private Sub Reset_Click()
    CountdownTimer.resetCountdown
    End Sub
Private Sub UserForm_Activate()
    startCounter
    End Sub
Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2013-03-06T16:40:22+00:00

The code requires that you have installed an add-in by Tushar Mehta, available from http://www.tushar-mehta.com/excel/software/vba_timer/

You must then set a reference in Tools | References... in the Visual Basic Editor to the TMTimer add-in.

The add-in is free for testing purposes, but you have to buy a license if you want to distribute it.

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2013-03-06T17:30:01+00:00

    Thank you!

    Was this answer helpful?

    0 comments No comments