2016-04-14 13 views
0

Bir e-posta HTML gövdesinde bir değerler aralığı kopyalamak istiyorum. E-postadaki bir aralığa kopyalama HTML gövdesi

Şimdiye kadar, burada başka bir eğilim sadece vücutta bir hücreyi kopyalamak için bir yol gördü ve çalışır:

Sub Macro1() 
    Dim mainWB As Workbook 
    Dim CCID 
    Dim SendID 
    Dim subject 
    Dim body 
    Dim otlApp 
    Dim OLmail As MailItem 

    Set otlApp = CreateObject("Outlook.Application") 
    Set OLmail = otlApp.CreateItem(olMailItem) 

    Dim oAttach As Outlook.Attachment 
    Dim sPath As String 

    SendID = NameToRange("Email_To") 
    subject = "Email1" 

    With OLmail 
     .To = SendID 
     If CCID <> "" Then 
      .cc = CCID 
     End If 
     .subject = subject 
     .Attachments.Add "S:\Documents\Graph1.jpeg", olByValue, 0 

     .HTMLBody = .HTMLBody & "<B>Hello,</B><br>" _ 
     & "<br><B>Introduction</B><br>" & _ 
        "<br>" & mainWB.range([101, 42],[102, 50]).Value & _ 
        "<br><B>Graph:</B><br>" _ 
        & "<img src='Graph1.jpg'" & "width='600' height='300'>" _ 

     .display 
    End With 
end sub 
+0

Sadece sorunuzu anlamaya çalışıyorsunuz. VBA ile bir e-postayı ayrıştırmaya mı çalışıyorsunuz? –

+0

VBA üzerinden bir e-posta gönderiyorum. Her şey çalışıyor, resim ve metin gönderiyorum. Şimdi, bu e-postada (html gövdesi) bir dizi değer göndermeye çalışıyorum ve mücadele ediyorum. – Spotless

+0

Tamam, orijinal kodunuzu oluştururken bazı web eğitimi, blog veya diğer yığın taşması sorusunu takip ettiğinizi varsayalım. Bunun için linki gönderir misiniz? Sorunuza bağlam sağlayacaktır. –

cevap

1

deneyin böyle içinden dizi daha sonra döngü tanımlamak.

Sub Macro1() 

Dim mainWB As Workbook 
Dim CCID 
Dim SendID 
Dim subject 
Dim body 
Dim otlApp 
Dim OLmail As MailItem 

'****************************** 
Dim rng As Range    '* 
Dim cell As Range   '* 
Dim EMBody As String   '* 
'****************************** 
Set rng = Range("") 'range '* 
For Each cell In rng   '* 
EMBody = EMBody & cell.Value '* 
EMBody = EMBody & Chr(13) '* 
Next cell     '* 
'****************************** 

Set otlApp = CreateObject("Outlook.Application") 
Set OLmail = otlApp.CreateItem(olMailItem) 

Dim oAttach As Outlook.Attachment 
Dim sPath As String 

SendID = NameToRange("Email_To") 
subject = "Email1" 

With OLmail 
    .To = SendID 
    If CCID <> "" Then .CC = CCID 
    End If 
    .subject = subject 
    .Attachments.Add "S:\Documents\Graph1.jpeg", olByValue, 0 
    .body = EMBody 
    .HTMLBody = "" 'put whatever else you need besides the range values 
    .display 
End With 

End Sub 
İlgili konular