VBA代码无法正常工作
我有以下代码不能正常工作。
Private Sub PrintNew_Click() If Sheets("New").Range("email").Value = 0 Then MsgBox "Email Address Needs to be Completed", vbInformation If response = vbCancel Then Exit Sub If MsgBox("Do you really want to print?", vbOKCancel) = vbOK Then Sheets("New").PrintOut copies:=1, Collate:=True Sheets("Disclosure").PrintOut copies:=1, Collate:=True If reponse = vbCancel Then Exit Sub End Sub
它工作正常,除了事实,如果我点击取消打印选项打印它仍然打印。
请告知需要修改的内容。
提前感谢任何帮助。 约翰戴维斯
您的response
拼写错误。 无论如何, 在打印之前 ,我会把这样的东西放在这样的地方,因为它更加地道,只需要less一个条件语句,因为之后你可以打印出来。 。 :
If MsgBox("Do you really want to print?", vbYesNo) <> vbYes Then Exit Sub
此外,正如Bathsheba在评论中提到的,您应该考虑使用Option Explicit
来防止类似于您的语法错误。 当Option Explicit
打开时,所有variables必须用Dim
/ ReDim
语句显式声明。 结果,试图使用一个未声明的variables,就像你在这里所做的那样,将会产生一个编译时错误,并清楚你的代码中的错误。