Vba:如何将发送给Outlook的范围左对齐为html? [英] Vba: How to align left a range send for outlook as html?

查看:142
本文介绍了Vba:如何将发送给Outlook的范围左对齐为html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是到目前为止我拥有的代码:

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

当此范围(另存为临时HTML文件)进入Outlook时,它将识别为表格,并且它们居中对齐.所以我的左边有空白空间.像这样:

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

如何使左对齐?

推荐答案

知道了!

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

这篇关于Vba:如何将发送给Outlook的范围左对齐为html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆