ต้องการแนบไฟล์ในเมลโดยอ้างข้อมูลในexcel
Posted: Sat Sep 08, 2018 8:58 pm
Code ด้านล่างคือผมไปเจอในเวปไซด์หนึ่งและลองนำมาประยุกต์ใช้
แต่ติดที่ไม่ค่อยมีความรู้เกี่ยว กับการใช้งานกับ Outlook ที่ผ่านมาทำแต่ในExcel
ผมต้องการแนบไฟล์เอกสารซึ่งข้อมูลที่อยู่และชื่อไฟล์อยู่บรรจุอยู่ในคอลัมน์"H"
รบกวนอาจารย์แนะนำด้วยครับ
แต่ติดที่ไม่ค่อยมีความรู้เกี่ยว กับการใช้งานกับ Outlook ที่ผ่านมาทำแต่ในExcel
ผมต้องการแนบไฟล์เอกสารซึ่งข้อมูลที่อยู่และชื่อไฟล์อยู่บรรจุอยู่ในคอลัมน์"H"
รบกวนอาจารย์แนะนำด้วยครับ
Sub SendEmailToAddressInCells()
Dim xRg As Range
Dim xRgEach As Range
Dim xRgVal As String
Dim xAddress As String
Dim xOutApp As Outlook.Application
Dim xMailOut As Outlook.MailItem
On Error Resume Next
xAddress = ActiveWindow.RangeSelection.Address
Set xRg = Application.InputBox("Please select mail supplier", "Supplier Evaluate", xAddress, , , , , 8)
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Set xOutApp = CreateObject("Outlook.Application")
Set xRg = xRg.SpecialCells(xlCellTypeConstants, xlTextValues)
For Each xRgEach In xRg
xRgVal = xRgEach.Value
If xRgVal Like "?*@?*.?*" Then
Set xMailOut = xOutApp.CreateItem(olMailItem)
'Dim Attach As Range
'Set Attach = Range(Cells(2, 12), Cells(Rows.Count, 12).End(xlUp)).Value
With xMailOut
.To = xRgVal
.Subject = "Evaluattion for August"
.CC = "Eva"
'.Attachments.Add (Attach)
.Body = "Dear supplier " & _
vbNewLine & vbNewLine & _
"This is an automatic mail for evaluation August " & _
vbNewLine & vbNewLine & _
"Please find the result as attached and sign and reply to us within 10 Sep 2018" & _
vbNewLine & vbNewLine & _
.Display
'.Send
End With
End If
Next
Set xMailOut = Nothing
Set xOutApp = Nothing
Application.ScreenUpdating = True
End Sub