Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook 2007 create macro to send all emails in a folder

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
I wrote code in Access to generate emails which end up in the drafts folder in Outlook 2007. then I move them to individual folders so I can examine them. If they are fine I want to send them out. I don't however want to open evey single one at time and hit the send button since there are hundreds.
Can I create a macro to send all the emails out in a folder called Grade 1? then click on a folder called "Grade 2" and send all of those out. etc. I have 9 folders.
I tried "moving" them to the outbox but they just sit there even after hitting send and receive.


DougP
 
If I understand correctly, this should work:
Code:
Public Sub Sendemails()

Dim mailItem As Long
Dim myOutlook As Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myFolders As Outlook.Folders
Dim myFolder As Outlook.MAPIFolder

'Send all items in the "Grade 1" folder that have a "To" address filled in.

'Setup Outlook

Set myOutlook = Outlook.Application
Set myNameSpace = myOutlook.GetNamespace("MAPI")
Set myFolders = myNameSpace.Folders

'Set Folder.  This will need modification based on where it's being run.
Dim foldername As String
Dim foldernumber As Double
foldername = "Grade "
For foldernumber = 1 To 9
    
    Set myFolder = myFolders("Personal Folders").Folders(foldername & foldernumber)
    
    'Loop through all Items
    
    For mailItem = myFolders.Items.Count To 1 Step -1
    
    'Check for "To" address and only send if "To" is filled in.
    
    If Len(Trim(myFolders.Items.Item(mailItem).To)) > 0 Then
    
    'Send Item
    
    myFolders.Items.Item(mailItem).Send
    
    End If
    Next mailItem
Next foldernumber
    
    'Clean-up
    
    Set myFolders = Nothing
    Set myNameSpace = Nothing
    Set myOutlook = Nothing
    
End Sub

 
How can we modify this to send emails in the current folder?
Say I select Grade1 for example then hit the marco button which sends out just those emails in the highlighted folder?

DougP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top