Sunday, April 21, 2019

To attach active work book and send to outlook

    To attach active work book and send to outlook




Dim objOutlook As Object
    Set objOutlook = CreateObject("Outlook.Application")
    Dim xStrDate As String
    Dim xJBName As String
   
    On Error GoTo ErrHandler
   
   
    xStrDate = Format(Now, "mm-dd-yyyy")
    xJBName = Workbooks("CENTRUM REPLENISHMENT TEMPLATE.xlsm").Sheets("Store Input").Range("B9").Value
    ' CREATE EMAIL OBJECT.
    Dim objEmail As Object
    Set objEmail = objOutlook.CreateItem(olMailItem)

    With objEmail
    .to = "celine.bautista@jollibee.com.ph"
    .CC = ""
    .BCC = ""
    .Subject = "CENTRUM: Order Template test2"
    .Body = "CENTRUM Order Template for " & xJBName & vbNewLine & "Date generated: " & xStrDate
    .Attachments.Add Application.ActiveWorkbook.FullName
    .Send
   
    End With
    ' CLEAR.
    Set objEmail = Nothing:    Set objOutlook = Nothing
       
      MsgBox "CENTRUM ORDER TEMPLATE SENT!"
   Exit Sub
       
       
ErrHandler:
Set OutMail = Nothing
Set OutApp = Nothing
err.Clear
MsgBox "Please manually send your File!"

No comments:

Post a Comment