0

我正在尝试创建一个宏,该宏从 excel 中获取表格并将其粘贴到电子邮件中并发送。我可以做到这一点,但表格仍然是表格,我想粘贴特殊图像。我尝试了很多不同的方法和很多谷歌搜索,但无济于事。请帮助...谢谢。

到目前为止的代码

TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"

'Copy the range and create a new workbook to past the data in
rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
    .Cells(1).PasteSpecial Format:="Picture (Enhanced Metafile)"  'Paste:=2
    .Cells(1).PasteSpecial xlPasteValues, , False, False
    .Cells(1).PasteSpecial xlPasteFormats, , False, False
    .Cells(1).Select
    Application.CutCopyMode = False

    On Error Resume Next
    .DrawingObjects.Visible = True
    .DrawingObjects.Delete
    On Error GoTo 0
End With


'Publish the sheet to a htm file
With TempWB.PublishObjects.Add( _
     SourceType:=xlSourceRange, _
     Filename:=TempFile, _
     Sheet:=TempWB.Sheets(1).Name, _
     Source:=TempWB.Sheets(1).UsedRange.Address, _
     HtmlType:=xlHtmlStatic)
    .Publish (True)
End With

'Read all data from the htm file into RangetoHTML
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.ReadAll
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
                      "align=left x:publishsource=")

'Close TempWB
TempWB.Close savechanges:=False
4

1 回答 1

0

以下是将所选表格复制为位图图片的代码,然后您可以使用标准粘贴命令将表格粘贴为图片。

Selection.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
于 2012-11-05T17:31:54.997 回答