davidfrommke
New Member
- Joined
- Sep 16, 2021
- Messages
- 4
- Office Version
- 365
- Platform
- Windows
Hello All -
I am attempting to come up with a macro that will allow me to click a button and move data from the excel spreadsheet and insert into an email.
The problem I have is that when I copy the information from Excel, it formats into the email differently. I would like to keep the same format / picture.
I have copied and pasted the VBA code I am using below.
I also have attachments showing what it looks like in Excel and what I actually get when I get it into Outlook.
Thank you for your help.
Dave
Sub Send_Email()
'Updated by Extendoffice 20200119
Dim xRg As Range
Dim I, J As Long
Dim xAddress As String
Dim xEmailBody As String
Dim xMailOut As Outlook.MailItem
Dim xOutApp As Outlook.Application
On Error Resume Next
xAddress = ActiveWindow.RangeSelection.Address
Set xRg = Application.InputBox("Please select range you need to paste into email body", "KuTools For Excel", xAddress, , , , , 8)
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Set xOutApp = CreateObject("Outlook.Application")
Set xMailOut = xOutApp.CreateItem(olMailItem)
For I = 1 To xRg.Rows.Count
For J = 1 To xRg.Columns.Count
xEmailBody = xEmailBody & " " & xRg.Cells(I, J).Value
Next
xEmailBody = xEmailBody & vbNewLine
Next
xEmailBody = "Hi" & vbLf & vbLf & " revised work schedule for following week" & vbLf & vbLf & xEmailBody & vbNewLine
With xMailOut
.Subject = "Revised work schedule for following week"
.To = johnsmith@smith.com
.Body = xEmailBody
.Display
'.Send
End With
Set xMailOut = Nothing
Set xOutApp = Nothing
Application.ScreenUpdating = True
End Sub
I am attempting to come up with a macro that will allow me to click a button and move data from the excel spreadsheet and insert into an email.
The problem I have is that when I copy the information from Excel, it formats into the email differently. I would like to keep the same format / picture.
I have copied and pasted the VBA code I am using below.
I also have attachments showing what it looks like in Excel and what I actually get when I get it into Outlook.
Thank you for your help.
Dave
Sub Send_Email()
'Updated by Extendoffice 20200119
Dim xRg As Range
Dim I, J As Long
Dim xAddress As String
Dim xEmailBody As String
Dim xMailOut As Outlook.MailItem
Dim xOutApp As Outlook.Application
On Error Resume Next
xAddress = ActiveWindow.RangeSelection.Address
Set xRg = Application.InputBox("Please select range you need to paste into email body", "KuTools For Excel", xAddress, , , , , 8)
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Set xOutApp = CreateObject("Outlook.Application")
Set xMailOut = xOutApp.CreateItem(olMailItem)
For I = 1 To xRg.Rows.Count
For J = 1 To xRg.Columns.Count
xEmailBody = xEmailBody & " " & xRg.Cells(I, J).Value
Next
xEmailBody = xEmailBody & vbNewLine
Next
xEmailBody = "Hi" & vbLf & vbLf & " revised work schedule for following week" & vbLf & vbLf & xEmailBody & vbNewLine
With xMailOut
.Subject = "Revised work schedule for following week"
.To = johnsmith@smith.com
.Body = xEmailBody
.Display
'.Send
End With
Set xMailOut = Nothing
Set xOutApp = Nothing
Application.ScreenUpdating = True
End Sub