2016-12-02 17 views
1

私は誰かが助けることを望んでいます。複数の添付ファイルをExcelを使用して自動メールで送信

私は電子メールアドレスの列を調べ、指定された添付ファイルを持つそれらのアドレスに個々の電子メールを送信するマクロをExcelに持っています。 マクロは完全に動作しますが、同じ電子メールで2つの添付ファイルを送信できるようにマクロを調整する方法は不明です。

助けてください。 完全なコードは次のとおりです。

Sub Send() 
'Working in Excel 2000-2016 
Dim OutApp As Object 
Dim OutMail As Object 
Dim sh As Worksheet 
Dim cell As Range 
Dim FileCell As Range 
Dim rng As Range 

With Application 
    .EnableEvents = False 
    .ScreenUpdating = False 
End With 

Set sh = Sheets("Email") 

Set OutApp = CreateObject("Outlook.Application") 

For Each cell In sh.Columns("B").Cells.SpecialCells(xlCellTypeConstants) 

    'Enter the path/file names in the C:Z column in each row 
    Set rng = sh.Cells(cell.Row, 1).Range("C1:Z1") 

    If cell.Value Like "?*@?*.?*" And _ 
     Application.WorksheetFunction.CountA(rng) > 0 Then 
     Set OutMail = OutApp.CreateItem(0) 

     With OutMail 
      .To = cell.Value 
      .Subject = cell.Offset(0, 7).Value 
      .HTMLBody = "<html><body><p>Hello " & cell.Offset(0, -1).Value & "<p></p>" _ 
      & cell.Offset(0, 2).Value & "</p><p>" _ 
      & cell.Offset(0, 3).Value _ 
      & Signature & "</body></html>" 

      For Each FileCell In rng.SpecialCells(xlCellTypeConstants) 
       If Trim(FileCell) <> "" Then 
        If Dir(FileCell.Value) <> "" Then 
         .Attachments.Add FileCell.Value 
        End If 
       End If 
      Next FileCell 

      .Send 
      '.Display 
     End With 

     Set OutMail = Nothing 
    End If 
Next cell 

Set OutApp = Nothing 
With Application 
    .EnableEvents = True 
    .ScreenUpdating = True 
End With 
End Sub 
+0

と二回

.Attachments.Add FileCell.Value 

ラインを実行することができますいいえ、スワップ '

' '

' –

答えて

2

あなたの添付ファイルの問題と関係が、あなたのHTMLの構文は次のとおりです。あなたの `.HTMLBody`ライン上で意識してはならない別の添付ファイルのパス

関連する問題