我有一个宏分配给一个形状,并希望密码保护这个宏,以便当单击形状时出现一个弹出框要求passwork,理想情况下,我想通过用户表单。编译错误:预期结束Sub
我已经看过了这个问题:How do you password protect excel VBA macro from running和做了什么我相信回答者说,所以我的代码如下:
Sub EmailExtract()
UserForm1.Show
***Code for the macro then follows***
End Sub
然后用户表格点击按钮:
Private Sub CommandButton1_Click()
If TextBox1.Value = "Password" Then 'Replace Password by your custom password
Sub EmailExtract() 'This is the sub that was being called by your button.
Else
MsgBox "You are not allowed to launch the macro"
End If
Exit Sub
End Sub
但是当我尝试运行此我得到就行了错误Compile error: Expected End Sub
:If TextBox1.Value = "Password" Then
是否有人可以告诉我我做错了什么?
你必须在'Exit Sub'后用'End If'关闭'If语句'' – DragonSamu
感谢您的建议,我刚刚尝试过,而且我仍然收到错误 –
难道你没有无限循环?你点击用户窗体上的按钮 - >启动子窗口'emailextract' - >打开我们之前两步的用户窗体 – psychicebola