0

I am using Excel VBA to generate an email in Outlook.

I would like to pass a variable value to the HTML code I am using to generate emails. The HTML code is lives in Sheet1!$A$1

How can I pass a variable value from a subroutine to the HTML code? I don't want to write out my HTML code in a module as writing it in VBA is painful!

VBA

Sub foo()
Dim myCustomVariable as string
myCustomVariable = "John Smith"
End Sub

HTML in Sheet1!$A$1

<html>
<body>
<p>Hello "myCustomVariable "</p>
</body>
</html>

1 Answer 1

1

Concatenate your tags and variables with &


.HTMLBody = "<p>" & Sheets("Sheet1").Range("A1") & "</p>"
Sign up to request clarification or add additional context in comments.

Comments

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.