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
Can anyone help me please?Code: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
MOD: please use CODE tags rather than QUOTE tags going forward... modified on this occasion for you.
Last edited by DonkeyOte; 01-14-2010 at 03:39 AM.
Maybe I'm missing something but there's nothing that I can see in your code that determines the actual content of each mail item .... and it is seemingly the content that is your concern, no ?
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
I am running an access data base with another macro to uploaded all emails to draft folder, then once I have all emails in draft forder I run this macro and there is when data gets mix.
I'm afraid you've lost me... all your code is doing is iterating the mail items in your Draft folder and mailing them if there's an address stipulated in the To field... what is actually in the email itself has nothing to do with the code you have posted.
Perhaps someone else can help as I'm drawing a blank I'm afraid.
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
facuse currently the code you have posted is the code in Outlook. This code only checks if there is a TO in the choosen folder and then sends it.
Getting out my crystal ball what you are doing here is generating emails in Access. and putting them all in one folder.
Then to avoid Microsofts inability to do get things right (Unavoidable Security Messages) you are sending them from outlook.
The data1 and party 2 choice is not in the code you have posted it is in the Access code that generates these emails.
If you are still having problems you need to post that code.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks