如何将粘贴在邮件正文和问候语上的图像居中?



我复制Excel工作表的不同区域,并将其粘贴为电子邮件正文中的图像。

我想把这些图片粘贴到邮件的中央。

Sub SendEmail()
Dim olApp As Outlook.Application
Dim olEmail As Outlook.MailItem
Dim olInsp As Outlook.Inspector
Dim wdDoc As Word.Document
Dim strGreeting As String
strGreeting = "Dear Someone," & vbNewLine
Set olApp = New Outlook.Application
Set olEmail = olApp.CreateItem(olMailItem)
With olEmail
.BodyFormat = olFormatRichText
.Display
.To = "Someone@tester.com"
.Subject = "Report"
Set olInsp = .GetInspector
Set wdDoc = olInsp.WordEditor
wdDoc.Range.InsertBefore strGreeting
wdDoc.Range.InsertAfter vbCrLf
Range("B1:O56").Copy
PasteAtEnd wdDoc
wdDoc.Range.InsertAfter vbCrLf
Range("B57:O111").Copy
PasteAtEnd wdDoc

wdDoc.Range.InsertAfter vbCrLf
Range("B112:O172").Copy
PasteAtEnd wdDoc
End With
End Sub
'paste from clipboard to the end of the document
Sub PasteAtEnd(doc As Word.Document)
With doc
.Content.Select
.Application.Selection.Collapse (wdCollapseEnd)
.Application.Selection.PasteAndFormat wdChartPicture
End With
End Sub

在Word中您可以center-align段落。例如:

For Each oILShp In ActiveDocument.InlineShapes
oILShp.Select
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Next

我可以使用下面的代码来居中所有的图像和问候:

设置wrange = wdDoc。范围(0,wdDoc.Characters.Count)

wdRange.ParagraphFormat.Alignment = wdAlignParagraphCenter

For i = 1 To wdRange.Tables.Count
wdRange.Tables(i).Rows.Alignment = wdAlignRowCenter
Next i

谢谢!

最新更新