Vba: How to align left a range send for outlook as html?

穿精又带淫゛_ 提交于 2020-01-25 09:43:07

问题


Here's the code that I have until now:

Dim objSelection As Excel.Range
Dim objTempWorkbook As Excel.Workbook
Dim objTempWorksheet As Excel.Worksheet
Dim strTempHTMLFile As String
Dim objTempHTMLFile As Object
Dim objFileSystem As Object
Dim objTextStream As Object
Dim objOutlookApp As Outlook.Application
Dim objNewEmail As Outlook.MailItem
Dim usuario As String
Dim linhaemail As Long

'Copy the selection that will be send using outlook'

Sheets("Padrão E-mail").Activate
ActiveSheet.Range("B1:K29").Select
Set objSelection = Selection
Selection.Copy

'Paste the copied selected ranges into a temp worksheet'
Set objTempWorkbook = Excel.Application.Workbooks.Add(1)
Set objTempWorksheet = objTempWorkbook.Sheets(1)

'Keep the values, column widths and formats in pasting'
 With objTempWorksheet.Cells(1)
    .PasteSpecial xlPasteValues
    .PasteSpecial xlPasteColumnWidths
    .PasteSpecial xlPasteFormats
 End With

'Save the temp worksheet as a HTML file'
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
strTempHTMLFile = objFileSystem.GetSpecialFolder(2).Path & "\Temp for Excel" & 
Format(Now, "YYYY-MM-DD hh-mm-ss") & ".htm"
Set objTempHTMLFile = objTempWorkbook.PublishObjects.Add(xlSourceRange, 
strTempHTMLFile, objTempWorksheet.Name, objTempWorksheet.UsedRange.Address)
objTempHTMLFile.Publish (True)
Set objTextStream = objFileSystem.OpenTextFile(strTempHTMLFile)

'Create a new email'
Set objOutlookApp = CreateObject("Outlook.Application")
Set objNewEmail = objOutlookApp.CreateItem(olMailItem)

'Read the HTML file data and insert into the email body'
 objNewEmail.HTMLBody = objTextStream.ReadAll

When this range (save as a temp HTML file) goes to Outlook, it recognizes as a table, and they are align center. So I have this empty space on left. Like this:

https://i.stack.imgur.com/Huinv.png

How can I make the left align?


回答1:


Got it!

objNewEmail.HTMLBody = "<table align=""left"">" & objTextStream.ReadAll & "</table>" & "<p align=""left"">" & objNewEmail.HTMLBody & "</p>"


来源:https://stackoverflow.com/questions/54930249/vba-how-to-align-left-a-range-send-for-outlook-as-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!