Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29748

extract numerous row to outlook email

$
0
0

I have the below code that when you highlight a row and run the macro, its opens a new outlook email and paste the relevant data in place to let a client know their package has been dispatched.

Sub GalleryTracking()
  'This assumes that Outlook is already open to simplify the code
  ''The 'Font Name' and 'Font Size' attributes are variables obtained from the Spreadsheet

  Dim OutApp As Object
  Dim OutMail As Object
  Dim var As Variant: var = Selection.Value
  Dim sBody As String
  Dim sFontName As String
  Dim sFontSize As String

  'Set the Font Name and Font Size
  sFontName = "Calibri"
  sFontSize = "11"'Get the Email Body from the cell
  sBody = "Hey"& ""& var(1, 1) & vbCrLf & vbCrLf & _
          "Your item has been dispatched. Please find the tracking details below (Please allow 12hrs for tracking to go live): "& vbCrLf & vbCrLf & _
          "consignment number: "& var(1, 26) & vbCrLf & vbCrLf & "Please track here:  "& " https://www.tnt.com/express/en_gb/site/shipping-tools/tracking.html?searchType=con&cons="& var(1, 26) & _
           vbCrLf & vbCrLf & _
          "IMPORTANT: Please note that when signing for the goods you must ensure you're satisfied with the packaging, if it looks damaged in any way please sign for as 'damaged'. 
   Please open your parcel with great care, particularly when using a knife to ensure that it does 
   not cut too deeply into the parcel damaging the item. You must inspect the goods promptly and 
    relay any issues to us within 24 hours, quoting reference "& var(1, 3) & "."& vbCrLf & 
   vbCrLf 
    & _
    "Have a great day, very best regards,"'Replace ASCII NEW LINE with HTML NEW LINE
    sBody = Replace(sBody, vbCrLf, "<BR>")                    'Converts text body to HTML
    sBody = Replace(sBody, vbLf, "<BR>")
    sBody = Replace(sBody, vbCr, "<BR>")


   'Attempt to create an Outlook object
    On Error Resume Next
    Set OutApp = GetObject(, "Outlook.Application")
    If Err.Number <> 0 Then
    Err.Clear
    MsgBox "NOTHING DONE.  The Outlook Object could not be created from Excel."& vbCrLf & _
           "Try again when Outlook is open."
     Exit Sub

     End If
     On Error GoTo 0


    'Create the Outlook Mail Object (using the default Email account)
    Set OutMail = OutApp.CreateItem(0)

    'Grab the Signature
    OutMail.Display                 'Creates .HTMLbody containing the signature

    'Determine the values to be sent
    With OutMail
    .To = var(1, 6)
    .CC = var(1, 13)
       .Subject = "Your Order Has Been Dispatched"'Put New .HTMLbody (containing font information)  around sBody (HTML body) and in front of 
    the signature .HTMLBody
    ' .HTMLBody = "<p style='font-family:"& Arial & ";13:"& sFontSize & "pt'>"& sBody & "</p>"& .HTMLBody    'Original - did not compile
      sFontName = "Calibri"
      sFontSize = "11"
     .HTMLBody = "<p style='font-family:"& sFontName & ";font-size:"& sFontSize & "pt'>"& 
    sBody & "</p>"& .HTMLBody

    .Display

    '.Send - comment out the 'Display line' if you want to send
   End With

   'Clear the Object Pointers
   Set OutMail = Nothing
   Set OutApp = Nothing



   End Sub

We are now going to be doing it a different way and contacting the branch with a list of items that were dispatched instead. So i need to do something similar so that when i highlight a group of rows and run it, it displays something along the lines of " The below clients items have been dispatched" and then a list of clients names, their reference and their tracking numbers. Lets just say those fields are in columns A,B and C to make it easier.

The email address will be similar to the above where it will be located in a cell, so if that can stay as data being pulled through, rather than a static one, thatd be great.


Viewing all articles
Browse latest Browse all 29748

Trending Articles