I am trying to run a macro on Outlook to send a lot of messages to different parties. The macro does work but the information that I am sending for each of them is unique so each of them should get different data but some how when I run the macro, data will mixed amount parties. Lets say that party 1 should get data 1 and party 2 should get data 2 and this is not happening, party 1 is getting data 2 and party 2 is getting data 1 or someone else data but not the one that belongs to it.
'macro
Public Sub SendDrafts()
Dim lDraftItem As Long
Dim myOutlook As Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myFolders As Outlook.Folders
Dim myDraftsFolder As Outlook.MAPIFolder
'Send all items in the "Drafts" folder that have a "To" address filled in.
'Setup Outlook
Set myOutlook = Outlook.Application
Set myNameSpace = myOutlook.GetNamespace("MAPI")
Set myFolders = myNameSpace.Folders
'Set Draft Folder. This will need modification based on where it's being run.
Set myDraftsFolder = myFolders("Mailbox's name").Folders("Drafts")
'Loop through all Draft Items
i = 1
For lDraftItem = myDraftsFolder.Items.Count To 1 Step -1
'Check for "To" address and only send if "To" is filled in.
If Len(Trim(myDraftsFolder.Items.Item(lDraftItem).To)) > 0 Then
i = i + 1
'Send Item
myDraftsFolder.Items.Item(lDraftItem).Display
myDraftsFolder.Items.Item(lDraftItem).Send
Start = Timer
Do While Timer < Start + TimeValue("00:00:21")
j = 1
Loop
'I added time to see it this was causing the issue but after it, I still got the issue.
End If
If i > 50 Then
GoTo tohere
End If
Next lDraftItem
tohere:
'Clean-up
Set myDraftsFolder = Nothing
Set myNameSpace = Nothing
Set myOutlook = Nothing
End Sub
Can anyone help me please?
MOD: please use CODE tags rather than QUOTE tags going forward... modified on this occasion for you.
Bookmarks