VBA Code that resumes if no input is done after a certain period of time

Kallassy

New Member
Joined
Jan 14, 2018
Messages
4
Hello,

I am trying to create a decision/choice game on excel using VBA.

When the user clicks on the "Start" button, the excel will display a hidden sheet with a riddle on it. On this sheet, the user is required to give a numerical answer in cell C5. I want the vba code to either continue running after an answer is written or to continue execution after 5 minutes, whichever comes first.

I appreciate all help.

Thank you !!
 

Logit

Well-known Member
Joined
Aug 31, 2016
Messages
2,936
.
This macro auto-closes the workbook after 30 seconds of inactivity. You can modify it to run the next part of your program instead of closing the program.

Code:
Option Explicit


Const idleTime = 30 'seconds
Dim Start
Sub StartTimer()
    Start = Timer
    Do While Timer < Start + idleTime
        DoEvents
    Loop
'///////////////////////////////////////////////////////
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    'Step 1: Declare your variables
    Dim ws As Worksheet
    'Step 2: Unhide the Starting Sheet
    Sheets("Sheet1").Visible = xlSheetVisible
    'Step 3: Start looping through all worksheets
    For Each ws In ThisWorkbook.Worksheets
    'Step 4: Check each worksheet name
    If ws.Name <> "Sheet1" Then
    'Step 5: Hide the sheet
    ws.Visible = xlVeryHidden
    End If
    'Step 6: Loop to next worksheet
    Next ws
    'Application.ScreenUpdating = True
    
    Range("A1").Select
    
    ThisWorkbook.Save
    
    'Application.DisplayAlerts = True
'//////////////////////////////////////////////////////////
    'Application.DisplayAlerts = False
    Application.Quit
    ActiveWorkbook.Close SaveChanges:=True
    
    Application.DisplayAlerts = True
End Sub
 

Forum statistics

Threads
1,085,580
Messages
5,384,565
Members
401,909
Latest member
dlo1503

Some videos you may like

This Week's Hot Topics

Top