2017-08-04 60 views
0

這裏是我用來複制範圍以及打開一個新的excel電子郵件的代碼。我可以同時複製和粘貼,但是我的問題是,當第二張圖片粘貼時,它將替換第一張圖片,而不是像我需要的那樣粘貼在上面。我究竟做錯了什麼?粘貼多個excel範圍作爲同一個Outlook電子郵件中的圖片

Private Sub CommandButton4_Click() 
'Finds last Row of email report 
Dim lRow As Long 
Dim lCol As Long 


lRow = Cells.Find(What:="*", _ 
     After:=Range("A1"), _ 
     LookAt:=xlPart, _ 
     LookIn:=xlFormulas, _ 
     SearchOrder:=xlByRows, _ 
     SearchDirection:=xlPrevious, _ 
     MatchCase:=False).row 

'Copy range of interest 
Dim r As Range 
Set r = Sheets("Email").Range(Cells(8, "E"), Cells(lRow, "N")) 
r.Copy 

'Open a new mail item 
Dim outlookApp As Outlook.Application 
Set outlookApp = CreateObject("Outlook.Application") 
Dim outMail As Outlook.MailItem 
Set outMail = outlookApp.CreateItem(olMailItem) 

With outMail 
    .To = "" 
    .CC = "" 
    .BCC = "" 
    .Subject = shift_txtb2.Text & " " & "Finishing Report" & " " & Format(Now(), "MM/DD/YY") 
    .HTMLBody = "" 
    'Attachments.Add 
    .Display 
End With 

''Get its Word editor 
outMail.Display 
Dim wordDoc As Word.Document 
Set wordDoc = outMail.GetInspector.WordEditor 

''To paste as picture 
wordDoc.Range.PasteAndFormat wdChartPicture 



Set r = Sheets("Email").Range("P8:T17") 
r.Copy 
wordDoc.Range.PasteAndFormat wdChartPicture 

Unload Me 
Sheets(1).Activate 
End Sub 
+0

https://stackoverflow.com/questions/38314574/pasting-two-excel作爲圖片的範圍 – braX

回答

0

把這個粘貼在第二個之前:

wordDoc.Content.InsertParagraphAfter 

你還可以嘗試:

wordDoc.Content.TypeParagraph 
+0

不幸的是,沒有工作,但我確實看到你來自哪裏。我移動了該行,並在代碼中嘗試了幾次,但獲得了相同的結果。 – accortdr

+0

我給了你另一個選項來嘗試。 – braX

+0

我不確定如果我運行的是不同於您的excel版本,但是我在第二個選項中收到了「方法或成員未找到錯誤」 – accortdr

相關問題