Consulting

Results 1 to 3 of 3

Thread: Sending Email in Excel VBA.

  1. #1
    VBAX Newbie
    Joined
    Feb 2020
    Posts
    2
    Location

    Sending Email in Excel VBA.

    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

  2. #2
    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
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Newbie
    Joined
    Feb 2020
    Posts
    2
    Location
    Thank you for your help !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •