skierpro720
New Member
- Joined
- Jul 20, 2018
- Messages
- 2
I am trying to send files to email addresses in cell A1 of a file within a folder path. Cell A1 of every file contains an email address. I am struggling to call the text in that cell in the ".To" section of myu script. In addition, the second "With" statement ends up attaching files 1 and 2, rather that file 2 exclusively. I would also like to disable the Outlook security warning I receive about another program trying to access Outlook. I would appreciate any help!
Sub Send_File_Outlook()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim SubjectLine As String
SubjectLine = "Subject A"
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Application.DisplayAlerts = False
strbody = "Line 1" & vbNewLine & vbNewLine & _
"Line 2"
On Error Resume Next
With OutMail
.To = Range("A1").("\\Filepath\FileName_1.xlsx")
.CC = ""
.BCC = ""
.Subject = SubjectLine
.Body = strbody
.Attachments.Add ("\\Filepath\FileName_1.xlsx")
.Display
.Send
End With
With OutMail
.To = Range("A1").("\\Filepath\FileName_2.xlsx")
.CC = ""
.BCC = ""
.Subject = SubjectLine
.Body = strbody
.Attachments.Add ("\\Filepath\FileName_2.xlsx")
.Display
.Send
End With
End Sub
Sub Send_File_Outlook()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim SubjectLine As String
SubjectLine = "Subject A"
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Application.DisplayAlerts = False
strbody = "Line 1" & vbNewLine & vbNewLine & _
"Line 2"
On Error Resume Next
With OutMail
.To = Range("A1").("\\Filepath\FileName_1.xlsx")
.CC = ""
.BCC = ""
.Subject = SubjectLine
.Body = strbody
.Attachments.Add ("\\Filepath\FileName_1.xlsx")
.Display
.Send
End With
With OutMail
.To = Range("A1").("\\Filepath\FileName_2.xlsx")
.CC = ""
.BCC = ""
.Subject = SubjectLine
.Body = strbody
.Attachments.Add ("\\Filepath\FileName_2.xlsx")
.Display
.Send
End With
End Sub