2017-11-09 19 views
0

私は、タイムシートを提出しなかった従業員にマネージャーの名前と電子メールアドレスのリストを持っています。 タイムシートを提出していない従業員の名前で各マネージャーに電子メールを作成するコードが必要です。何かアドバイス?ファイルはExcelからパーソナライズされた電子メールを送信するには?

approval name Approval Email address Employee name 
test 1   [email protected]    Test 11 
test 2   [email protected]  test 10 
test 3   [email protected]   test 9 

の下にど​​のようにこの以来

sub sendmultiple() 
' 
    Dim xOTApp As Object 
    Dim xMItem As Object 
    Dim xCell As Range 
    Dim xRg As Range 
    Dim xEmailAddr As String 
    Dim xTxt As String 
    On Error Resume Next 
    xTxt = ActiveWindow.RangeSelection.Address 
    Set xRg = Application.InputBox("Please select the addresses list:", "Kutools for Excel", xTxt, , , , , 8) 
    If xRg Is Nothing Then Exit Sub 
    Set xOTApp = CreateObject("Outlook.Application") 
    For Each xCell In xRg 
     If xCell.Value Like "*@*" Then 
      If xEmailAddr = "" Then 
       xEmailAddr = xCell.Value 
      Else 
       xEmailAddr = xEmailAddr & ";" & xCell.Value 
      End If 
     End If 
    Next 
    Set xMItem = xOTApp.CreateItem(0) 
    With xMItem 
     .To = xEmailAddr 
     .Display 
    End With 
End Sub 
+2

これは、多くのレベルで間違っています。 [ask]を読んで[tour]を取る。これはコードを書くサービスではなく、VB.NETコードではありません。もちろん、それを読みやすくするために書式化することをやってもかまいません。 – Plutonix

答えて

0

は宿題のように見える1つの電子メールの代わりに、各メンバーに送信するためにコードを変更するように見える、私はあなたのことを示し、非機能のサンプルをあげますあなたの一般的な構造

0

小さな変更を加えれば、あなたが望むものを正確に行うことができるはずです。

In column A : Names of the people 
In column B : E-mail addresses 
In column C:Z : Filenames like this C:\Data\Book2.xls (don't have to be Excel files) 

The Macro will loop through each row in "Sheet1" and if there is a E-mail address in column B 
and file name(s) in column C:Z it will create a mail with this information and send it. 

Sub Send_Files() 
'Working in Excel 2000-2016 
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm 
    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("Sheet1") 

    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 = "Testfile" 
       .Body = "Hi " & cell.Offset(0, -1).Value 

       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 'Or use .Display 
      End With 

      Set OutMail = Nothing 
     End If 
    Next cell 

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

https://www.rondebruin.nl/win/s1/outlook/amail6.htm

関連する問題