Hey all,
I have a macro that copies an Excel range and inserts it into a new Outlook email. However, the problem I’m facing is that VBA is centering the image instead of aligning it to the left as usual. Could someone review my code and suggest changes to ensure the image is pasted on the left?
Sub SENDEMAIL()
'EMAIL TO STO/STAFF DISTRO OPTION
Dim OApp As Object
Dim OMail As Object
Dim tempFileName As String, newPath As String
newPath = ThisWorkbook.path & "\"
tempFileName = newPath & "temp.html"
'Publish as webpage
With ThisWorkbook.PublishObjects.Add(xlSourceRange, _
tempFileName, "Inhouse_Email", "$A29:$J44", xlHtmlStatic, _
, "")
.Publish (True)
.AutoRepublish = False
End With
'Read the html file in a string in one go
Dim MyData As String
Open tempFileName For Binary As #1
MyData = Space$(LOF(1))
Get #1, , MyData
Close #1
Kill tempFileName
Set OApp = CreateObject("Outlook.Application")
Set OMail = OApp.CreateItem(0)
quote = ""
With OMail
.To = Range("B20").Value
.CC = Range("B21").Value
.Subject = Range("B22").Value
.Display
.HTMLBody = "<p align='left'>" & _
MyData & _
"</p>" & _
.HTMLBody
End With
With OMail
.Attachments.Add Range("B26").Value
End With
Set OMail = Nothing
Set OApp = Nothing
MsgBox "Email Sent"
End Sub
I have a macro that copies an Excel range and inserts it into a new Outlook email. However, the problem I’m facing is that VBA is centering the image instead of aligning it to the left as usual. Could someone review my code and suggest changes to ensure the image is pasted on the left?
Sub SENDEMAIL()
'EMAIL TO STO/STAFF DISTRO OPTION
Dim OApp As Object
Dim OMail As Object
Dim tempFileName As String, newPath As String
newPath = ThisWorkbook.path & "\"
tempFileName = newPath & "temp.html"
'Publish as webpage
With ThisWorkbook.PublishObjects.Add(xlSourceRange, _
tempFileName, "Inhouse_Email", "$A29:$J44", xlHtmlStatic, _
, "")
.Publish (True)
.AutoRepublish = False
End With
'Read the html file in a string in one go
Dim MyData As String
Open tempFileName For Binary As #1
MyData = Space$(LOF(1))
Get #1, , MyData
Close #1
Kill tempFileName
Set OApp = CreateObject("Outlook.Application")
Set OMail = OApp.CreateItem(0)
quote = ""
With OMail
.To = Range("B20").Value
.CC = Range("B21").Value
.Subject = Range("B22").Value
.Display
.HTMLBody = "<p align='left'>" & _
MyData & _
"</p>" & _
.HTMLBody
End With
With OMail
.Attachments.Add Range("B26").Value
End With
Set OMail = Nothing
Set OApp = Nothing
MsgBox "Email Sent"
End Sub