2

I have the following code, which gives me the Compile error: "Expected: End of Statement" in the Subject line of code after the "Inc" Range.

This code is part of a module which opens MS Outlook email and enters data from specific cells in the data sheet (generated from a Userform) in to the Subject field of the email.

The code:

'This bit tells it where to send the email to, what the subject line is etc
    .to = "[email protected]"
    .CC = "[email protected]"
    .BCC = ""
    .Subject = "Inc" Range("H6").Value & " " & Range("G12").Value & " - " & Range("G14").Value & " " & Range("H8").Value
    .HTMLBody = RangetoHTML(rng)
    .Display

   End With
   On Error GoTo 0

Is this sufficient information?

1 Answer 1

2

Can you check if it's because is missing the "&" operator

.Subject = "Inc"  Range("H6").Value & " " & Range("G12").Value & " - " & Range("G14").Value & " " & Range("H8").Value

Should be

.Subject = "Inc" & Range("H6").Value & " " & Range("G12").Value & " - " & Range("G14").Value & " " & Range("H8").Value
Sign up to request clarification or add additional context in comments.

3 Comments

On Error Goto 0 reset the error handler to its default, why do you think it isn't good practice?
Corrected my previous message, I read some documentation and you are right (here analystcave.com/vba-proper-vba-error-handling) about is the only way to reset the error handler. Thanks for correcting me. @VincentG
Thank you (apologies for the delay in response.

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.