Prevent Windows from Locking when Idle Using Excel VBA

Prevent Windows from Locking Using Excel VBA:

In remote work, a small yet powerful code can be a game-changer. Especially useful in work-from-home scenarios, it can effectively prevent applications like Teams and Skype from locking you out, eliminating the need to enter your password multiple times. What’s even better is that you don’t require any admin rights to make this happen. In this blog post, we’ll guide you through using Excel VBA to achieve this seamless experience and keep your Windows from locking, ensuring uninterrupted productivity.

Step by Step Guide

  • Step 1 – Create a new Excel File on the Desktop. Rename it with Any Name and Save.
  • Step 2 – Right Click on any “Sheet”. Click on View Code.
  • Step 3 – Paste the code below in the VBA Code Editor.
Prevent Windows from Locking
Prevent Windows from Locking when Idle Using Excel VBA
Sub Unlocking()

Dim i As Integer

For i = 1 To 1000

Application.SendKeys ("^s")

Application.Wait (Now + TimeValue("0:00:10"))

Next i

End Sub

  • Step 4 – Now, Click on the Developer Tab, Then Macros, and run the Macro.


This code keeps saving the file at intervals of 15 seconds until you press the ‘Esc’ key. Furthermore, it ensures that the loop continues to run, & Prevents Windows from Locking when Idle.

Leave a Reply

Your email address will not be published. Required fields are marked *