2017-07-02 673 views
3

我想嵌入工作表作爲圖像在Outlook郵件正文的範圍。它正確保存圖片,但我只在Outlook郵件正文中看到空白圖片。我在這裏做錯了什麼?嵌入圖片在Outlook郵件正文excel vba

Sub View_Email() 

    tName = Trim(MAIN.Range("tEmail")) 

    If Not tName Like "*@*.*" Then MsgBox "Invalid Email address": Exit Sub 

    Set OutApp = CreateObject("Outlook.Application") 
    Set OutMail = OutApp.CreateItem(0) 

    'File path/name of the gif file 
    Fname = ThisWorkbook.Path & "\Claims.jpg" 

    Set oCht = Charts.Add 

    STAT.Range("A3:G26").CopyPicture xlScreen, xlBitmap 
    With oCht 
     .Paste 
     .Export Filename:=Fname, Filtername:="JPG" 
     '.Delete 
    End With 

    On Error Resume Next 
    With OutMail 
     .To = tName 
     .CC = "" 
     .BCC = "" 
     .Subject = STAT.Range("C1").Value 
     .HTMLBody = "<html><p>Summary of Claim Status.</p>" & _ 
        "<img src=" & Fname & "' height=520 width=750>" 
     .display 
     '.Send 'or use .Display 
    End With 
    On Error GoTo 0 

    'Delete the gif file 
    'Kill Fname 

    Set OutMail = Nothing 
    Set OutApp = Nothing 
End Sub 
+0

調試代碼,並檢查什麼是Fname'的'價值和手動檢查文件是否存在。打開文件並檢查圖表是否已導出 –

+0

@SiddharthRout是的,我確實檢查了fname和圖片,他們都顯得很好,但是outlook主體將圖片顯示爲空白 – newguy

+0

哦,我知道爲什麼...一刻發佈答案 –

回答

3

您需要添加圖像並隱藏它。位置0將添加並隱藏它。

.Attachments.Add Fname, 1, 0 

1是展望恆olByValue

一旦你添加的圖像,然後你必須使用"cid:FILENAME.jpg",如下圖所示。

試試這個

With OutMail 
    .To = tName 
    .CC = "" 
    .BCC = "" 
    .Subject = STAT.Range("C1").Value 
    .Attachments.Add Fname, 1, 0 
    .HTMLBody = "<html><p>Summary of Claim Status.</p>" & _ 
       "<img src=" & "cid:Claims.jpg" & "height=520 width=750>" 
    .Display 
End With 

截圖

enter image description here

+1

非常感謝它完美地工作。 – newguy

相關問題