Copy excel table to outlook mail and keep the format

后端 未结 2 428
暖寄归人
暖寄归人 2021-01-16 21:36

I am using VBA to send emails of a range of cells within excel. The size of the table goes haywire and all the text being wrap up when I copy over to outlook.

I wo

2条回答
  •  粉色の甜心
    2021-01-16 22:09

    You can do it by breaking into parts.

    First you will need to extract the data you need to a new worksheet. You can delete the worksheet later.

    If you wish to copy the format as well, you can use something like ThisWorkbook.Sheets("Copy").Range("A1").PasteSpecial Paste:=xlPasteFormats. You might need xlPasteFormats, xlPasteColumnWidths & xlPasteValues.

    To create new worksheet: Sheets.Add(, Sheets(Sheets.Count)).name = "worksheetName"

    MailEnvelop Example

    Sub sendEmail()
    
    ThisWorkbook.EnvelopeVisible = True
    
    With ThisWorkbook.Sheets("Copy").MailEnvelope
      .Introduction = "This is the email message"
      .Item.To = "abc@domain.com"
      .Item.Subject = "Subject"
      .Item.Send
    
    End With
    
    ThisWorkbook.EnvelopeVisible = False
    
    'Delete the the worksheet
    ThisWorkbook.Sheets("Copy").Delete
    
    End Sub
    

    Read here for some good guidelines: https://www.rondebruin.nl/win/s1/outlook/mail.htm

提交回复
热议问题