April 27, 2024

MoDCore

Welcome to the core

Randomly Quit Excel – VBA

Annoying, or clever, you decide how you use it!

When Excel is opened, it sets a variable (Close_Var) equal to 30, and then chooses a random number. If that random number is less than 30, Excel immediately closes without warning. When the workbook is opened it has the chance to close instantly 30% of the time!

Private Sub Workbook_Open()
   Application.DisplayAlerts = False
   Randomize
   Close_Var = 30
   Rand_Num = 100 * Rnd
   If Close_Var > Rand_Num Then
         Application.Quit
   End If
End Sub
Copyright © All rights reserved. | Newsphere by AF themes.