Im using the code below to copy different ranges of an excel sheet as image and paste on a email body. Its working fine, but I want to paste this images centered on the email, thats my question...
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 = "[email protected]"
.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
CodePudding user response:
In Word you can center-align
paragraphs. For example:
For Each oILShp In ActiveDocument.InlineShapes
oILShp.Select
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Next
CodePudding user response:
I was able to center all the images and the greeting using the code below:
Set wdRange = wdDoc.Range(0, wdDoc.Characters.Count)
wdRange.ParagraphFormat.Alignment = wdAlignParagraphCenter
For i = 1 To wdRange.Tables.Count
wdRange.Tables(i).Rows.Alignment = wdAlignRowCenter
Next i
Thanks!