I have a VBscript that runs SAP and downloads a file and inturn runs a macro on the file then saves and emails.

The problem is I have a list of 8 email addresses to send the file to but Outlook only sends to 3-4 people before closing. Once you reopen outlook it will finish sending the remaining emails.

Anyone know of a way of delaying Outlook from closing until it finishes sending all emails?

I tried a wait script but it didn't seem to solve the problem.

I tried to use a `Wait` statement before and after the end with just before
 `Set objOutlook = Nothing`:

```
'sending e mail with attachment
set app = CreateObject("Excel.Application")
Set wb = app.Workbooks.Open ("B:\GLOBAL\2063-BASUS\WYANDOTTE\CMN\CM Supply Chain\CM Customer Care Team\HOM Reports\CM Hom Archive\HOM Contacts\HomContacts.xlsx")
'skip header row. set to 1 if you
'don't have a header row
set sh = wb.Sheets("Sheet1")
row = 1
email = sh.Range("A" & row)
LastRow = sh.UsedRange.Rows.Count
For r = row to LastRow
    If App.WorkSheetFunction.CountA(sh.Rows(r)) <> 0 Then 
        SendMessage email
        row = row + 1
        email = sh.Range("A" & row)
      End if
Next
wb.close
set wb = nothing
set app = nothing

Sub SendMessage(EmailAddress)

  ' Create the Outlook session.
  Set objOutlook = CreateObject("Outlook.Application")

  template = FindTemplate()

  ' Create the message.
  Set objOutlookMsg  = objOutlook.CreateItem(0)

  With objOutlookMsg
      ' Add the To recipient(s) to the message.
      Set objOutlookRecip = .Recipients.Add(EmailAddress)
      objOutlookRecip.resolve
      objOutlookRecip.Type = 1

     ' Set the Subject, Body, and Importance of the message.
     .Subject = "Todays Hom Report"
     .bodyformat = 3
     .Importance = 2  'High importance
     body = "Please do not reply to e mail as this is unmanned"

     if not isNull(AttachMentPath) then
       .Attachments.add "B:\GLOBAL\2063-BASUS\WYANDOTTE\CMN\CM Supply Chain\CM Customer Care Team\HOM Reports\hom_script\Hom Export\Hom Report.xlsx"
     end if

     .HTMLBody = body

     ' Should we display the message before sending?
     If DisplayMsg Then
         .Display
     Else
         .Save
         .Send
     End If
    End With
    Set objOutlook = Nothing
End Sub

Function FindTemplate()
    Set OL = GetObject("", "Outlook.Application")
    set Drafts = OL.GetNamespace("MAPI").GetDefaultFolder(16)
    Set oItems = Drafts.Items

    For Each Draft In oItems
        If Draft.subject = "Template" Then
            FindTemplate = Draft.HTMLBody
            Exit Function
        End If
    Next
End Function

```

There are no error messages. It sends emails to about 3-4 email addresses and won't finish sending the remainder until I reopen outlook. This will be running on an unmanned server with scheduler.