VBA is centering the image instead of aligning it to the left as usual in New Email

hvp2262

New Member
Joined
Sep 20, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Forum statistics

Threads
1,221,544
Messages
6,160,427
Members
451,645
Latest member
androidmj

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top