PDA

View Full Version : Sending Email in Excel VBA.



CRT54
02-06-2020, 04:35 PM
Hello,

My issue is using a variable containing a string of data (#1.) VS assigning a string to a variable (#2.).

1. I'm referencing cell "A2" which contains: "Hello Mike Jones," & vbNewLine "Have a nice day" & vbNewLine

My code in VBA :

Dim sMessage As String

sMessage = Range("A2")

Results: "Hello Mike Jones," & vbNewLine "Havew a nice day" & vbNewLine


2. Assigning a string to a variable.

Dim sMessage1 As String

sMessage1 = "Hello " & Name & "," & vbNewLine & vbNewLine & "Have a nice day" & vbNewLine

Results when doing debug.print sMessage1 :

Hello Mike Jones,

Have a nice day


Is there a way (function, method. etc...) that I can get the same results in step 1. as I have in step 2.

Thanks you,
Claude

gmayor
02-06-2020, 11:57 PM
If the cell simply contains the text string as you have written it then the answer is no. If you have inserted the line breaks in the cell itself, then the result should be as in 2.

Surely it would make more sense to put just the name in the cell and build the string in code e.g.


sMessage = "Hello" & Range("A2") & vbcr & vbcr & "Have a nice Day" & vbcr

CRT54
02-08-2020, 05:44 AM
Thank you for your help !