如何使用密码设置注销在文本框中是错误的?

时间:2016-10-27 01:23:20

标签: vba excel-vba excel

enter image description here

 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/

错误

固定长度的字符串不允许作为对象模块的公共成员的类型;私有对象模块不允许作为公共对象模块的公共成员的类型

1 个答案:

答案 0 :(得分:1)

是的还是编译错误:

enter image description here

这条消息有点神秘,但它所说的是你不能在用户窗体中放置公共 WinAPI函数(例如,Public Declare Function...)或类模块。您可以通过将其声明为Private

来解决此问题
Private Declare Function ExitWindowsEx Lib "user32" _
    (ByVal dwOptions As Long, _
    ByVal dwReserved As Long) As Long

或者,您可以将其放在标准代码模块中并保留Public,这样就可以从其他模块,类,表单等访问它。

enter image description here