Public Declare Function ExitWindowsEx Lib "user32" _
(ByVal dwOptions As Long, _
ByVal dwReserved As Long) As Long
Private Sub CommandButton1_Click()
If TextBox2 <> "123" Then
ExitWindowsEx 4, 0 'log off
Else
ExitWindowsEx 1, 0 'shut down
End Sub
我只參考這個
http://officetricks.com/logoff-or-shutdown-computer-with-excel/
錯誤固定長度字符串不允許作爲目標模塊的公共成員的類型;私有對象模塊不允許作爲一個公共目標模塊
如果錯誤發生在行說'ExitWindowsEx 4,0 //登錄off'和'ExitWindowsEx 1,0 // down'關閉那是因爲''//不合法VBA。如果你的錯誤是別的,你需要告訴我們它是什麼。 – YowE3K
@ YowE3K我沒有在我的代碼中使用'//''。錯誤消息更新 – evabb