0

I have the following code that is not working properly.

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

It works ok apart from the fact that if I click cancel on the option to print it still prints.

Please advise what needs to be amended.

Thanks in advance of any help. John Davies

0

1 Answer 1

3

Your response is misspelled. In any case, I would place something like this before you print out, as it is much more idiomatic and requires one less conditional statement, as you can just print out afterwards. . :

If MsgBox("Do you really want to print?", vbYesNo) <> vbYes Then Exit Sub

Also, as mentioned by Bathsheba in the comments, you should consider using Option Explicit to prevent syntactical errors like yours. When Option Explicit is on, all variables must be declared explicitly with Dim/ReDim statements. Resultantly, attempting to use an undeclared variable as you did here will produce a compile-time error and clear direction as to the fault in your code.

Sign up to request clarification or add additional context in comments.

1 Comment

I prefer <> vbYes as it gives you more stability. Also mention Option Explicit as a way of catching the misspelling.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.