0

我有这段代码可以将范围粘贴到电子邮件中,但是作为文本,有没有办法可以修改它,以便可以将范围粘贴为图片?我需要它的原因是因为我要粘贴的某些单元格有数据栏,这些不会显示在电子邮件中,如果您有解决方案,它也会有所帮助提前谢谢

Sub SaveImage()

Dim tmp As Variant, str As String, h As Double, w As Double

Dim Rng As Range
Set Rng = Nothing
Set Rng = ThisWorkbook.Worksheets("Week Effectivity").Range("A1:M15").SpecialCells(xlCellTypeVisible)


Dim OA, OM As Object
Set OA = CreateObject("Outlook.Application")
Set OM = OA.CreateItem(0)

With OM
.To = "email"
'.CC = "email"
.Subject = "por ahi va"
 
 .HTMLBody = RangetoHTML(Rng)
 .Pictures.Paste
.Send

End With
Set OM = Nothing
Set OA = Nothing

Application.PrintCommunication = True
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.StatusBar = False

End Sub


Function RangetoHTML(Rng As Range)
    Dim FSO As Object
    Dim ts As Object
    Dim TempFile As String
    Dim TempWB As Workbook
   ' PDF_FILE = ""
    TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".html"
  
    ' Copy the range and create a workbook to receive the data.
    Rng.Copy
    Set TempWB = Workbooks.Add(1)
    With TempWB.Sheets(1)
        .Cells(1).PasteSpecial Paste:=8
        .Cells(1).PasteSpecial xlPasteValues, , False, False
        .Cells(1).PasteSpecial xlPasteFormats, , False, False
        .Cells(1).PasteSpecial xlPasteAllMergingConditionalFormats, , False, False
        Application.CutCopyMode = False
        On Error Resume Next
        .DrawingObjects.Visible = True
        On Error GoTo 0
    End With
  ' Publish the sheet to an .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 the RangetoHTML subroutine.
    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
  
    ' Delete the htm file.
    Kill TempFile
    
    Set ts = Nothing
    Set FSO = Nothing
    Set TempWB = Nothing
    Application.CutCopyMode = True
End Function
4

0 回答 0