excel 我怎样才能使粘贴在邮件正文和问候语上的图片居中?

iqih9akk  于 2023-03-13  发布在  其他
关注(0)|答案(2)|浏览(201)

我复制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
kzipqqlq

kzipqqlq1#

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

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

ruarlubt2#

我可以使用下面的代码将所有图像和问候居中:
设置wdRange = wdDoc.范围(0,wdDoc.字符数)

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

谢谢!

相关问题