2017-03-09 7 views
0

Excelのスプレッドシートのデータに応じて添付ファイル付きの電子メールを送信するインターネット上のコードが見つかりました。コードは完璧に動作しますが、私が知りたいのは、電子メールの送信元のメールボックスをどのように変更できるのでしょうか?現在は、送信メールボックスを押したユーザーから送信されます。のは、メールボックスの[email protected]を呼びましょう、私の例のためにVBAで電子メールを送信するマクロに送信者を追加するには

Sub Send_Files() 
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("Sending Tool") 

Set OutApp = CreateObject("Outlook.Application") 

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

    'Enter the File Path in E1, you can add more files and extend the range if needed 
    Set rng = sh.Cells(cell.Row, 1).Range("E1:K1") 

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

     With OutMail 
      .to = cell.Value 
      .Subject = "Email Header" 
      ' This is the body of the email, change the next line to change the email's contents. use "<br>" to create a line break in the email 
      .HTMLBody = "Good Morning " & cell.Offset(0, -3).Value & "," & "<br>" & "<br>" & "Body" 
      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 

MsgBox ("Emails Sent Successfully") 

End Sub 

、:彼らは、ユーザーがアクセス権を持つ特定のメールボックスから来以下のコードを参照してくださいするためしかし、私が望むことです私はこれを送信メールボックスにして、受信者が返信したい場合は、ユーザーの個人メールではなく返信してください。

+1

http://www.rondebruin.nl/win/s1/outlook/account.htmネイサンは、私が使用して終了助けを – SJR

答えて

0

てみ

.ReplyRecipientNames = "[email protected]" 
+0

ありがとう: '.SentOnBehalfOfName =「Userhelp @ example.co.uk " .To = cell.Value .Subject =" Eail Header "' – JFewtrell

+2

このコードスニペットは質問を解決するかもしれないが[説明を含む](http://meta.stackexchange.com/questions/114762/explain-entire-code-based-answers)は本当にあなたの投稿の質を向上させるのに役立ちます。将来読者の質問に答えていることを覚えておいてください。そうした人々はあなたのコード提案の理由を知らないかもしれません。 – DimaSan

関連する問題