1

How to lock computer using excel VBA? Just in case, by "lock computer" I mean same effect when you do "start menu --> shutdown --> Lock".

RealLifePM
  • 60
  • 2
  • 7
  • Sorry, it is a duplicated one. "Simulate windowskey+L in visual basic" solves this qeustion as brettdj suggested. – RealLifePM Jun 14 '16 at 07:36

1 Answers1

1

For a x64 bit:

Option Explicit

Private Declare PtrSafe Function LockWorkStation Lib "user32.dll" () As Long

Private Sub LockStation()
    LockWorkStation
End Sub

For x32 bit:

I think it's like this, can't test as I don't have a 32bit pc.

Option Explicit

    Private Declare Function LockWorkStation Lib "user32.dll" () As Long

    Private Sub LockStation()
        LockWorkStation
    End Sub

Happy coding.

James Heffer
  • 686
  • 1
  • 6
  • 17