Solved

Outlook or Word or Access Macro (VBA) - Open a series of emails in the outbox one at a time, change some parameters and email each one

Posted on 2011-09-18
5
315 Views
Last Modified: 2012-05-12
Outlook or Word or Access Macro (VBA) - Open a series of emails in the outbox one at a time, change some parameters and email each one

Currently I have a process to use word merge to create emails to respond to bid questions. When I have Outlook set to work off line, each of the emails is saved in the outbox.

I then open each email, add an attachment, change priority, request a read deceipt and received receipt and sme times change the sent from address to an alaternate address before sending.

For 2-5 emails this is easily done manually, but for 20-25 emails its not so simple. I'd like to write a macro or vba code to run from word or access to automate this process. Can anybody help?

Thyanks
0
Comment
Question by:rogerdjr
  • 4
5 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 36558282
So for each of the mails in outbox at the time of running the macro you want to take this set of actions and if so how is the change in sender to be controlled

Chris
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 36558413
OK, I do not have 2007 or later in front of me .. and accounts is a proerty associated with these versions so if sendusing is always to be set the following with the commented lines in amendOutbox enabled ought to work ... haven't been able to validate the function but hopefully I recall all correctly.


Sub amendOutbox()
Dim mai As mailitem 'Object
Dim acct As Long

'    acct = getAccount
    'If acct = 0 Then acct = 1
    For Each mai In Application.Session.GetDefaultFolder(olFolderOutbox).items
        If mai.Class = olMail Then
            With mai
                .Importance = olImportanceHigh
                .ReadReceiptRequested = True
                .OriginatorDeliveryReportRequested = True
                .Attachments.Add "c:\deleteme\testname.doc", olEmbeddeditem
'                .sendusingaccount = Application.Session.Accounts.item(1)
' Need to establish the account required ... but once set can be hard coded.
                .Send
            End With
        End If
    Next

End Sub

Function getAccount() As Long
Dim i As Long
    
' Accounts only valid for 2007 and on!
'can embed it as Access call if required via:
' acct = getaccount()
    
    For i = 1 To Application.Session.Accounts.Count
        If (MsgBox("Use Account " & Application.Session.Accounts.item(i).smtpaddress, vbYesNo)) = vbYes Then 'application.Session.accounts.item(i)
            getAccount = i
            Exit For
        End If
    Next

'    MsgBox "account selected as :> " & getAccount

End Function

Open in new window

0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 36561615
I have just tested getaccounts and it works fine so should do as required ... in the case of 2007 and later

Chris
0
 

Author Closing Comment

by:rogerdjr
ID: 36562416
Works great - thanks

A quick question - if I wanted to run this from access or word, can you help me add the code to:

1) Set Outlook to work off line
2) search for the outbox (after the merge has run)
3) run this code
4) set outlook to work on-line and send all the messages (one at a time).

I know this is essentially a new question but it is directly related.

Thanks
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 36562641
Switch everything to late binding i.e.:

Chris
Sub amendOutbox()
Dim olkApp As Object
Dim mai As Object
Dim acct As Long

'    acct = getAccount
    'If acct = 0 Then acct = 1
    Set olkApp = CreateObject("outlook.application")
    For Each mai In olkApp.Session.GetDefaultFolder(4).items
        If mai.Class = 43 Then
            With mai
                .Importance = 2
                .ReadReceiptRequested = True
                .OriginatorDeliveryReportRequested = True
                .Attachments.Add "c:\deleteme\testname.doc", 5
'                .sendusingaccount = olkapp.Session.Accounts.item(1)
' Need to establish the account required ... but once set can be hard coded.
                .Send
            End With
        End If
    Next

End Sub

Function getAccount() As Long
Dim olkApp As Object
Dim i As Long
    
' Accounts only valid for 2007 and on!
'can embed it as Access call if required via:
' acct = getaccount()
    
    Set olkApp = CreateObject("outlook.application")
    For i = 1 To olkApp.Session.Accounts.Count
        If (MsgBox("Use Account " & olkApp.Session.Accounts.Item(i).smtpaddress, vbYesNo)) = vbYes Then 'olkApp.Session.accounts.item(i)
            getAccount = i
            Exit For
        End If
    Next

'    MsgBox "account selected as :> " & getAccount

End Function

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Problem: You created a new custom form in Outlook for your contacts (added fields, deleted fields, changed the layout of fields, whatever) and made it the default form for contacts. The good news is that all new contacts will utilize the new form. T…
This article will show you how to use shortcut menus in the Access run-time environment.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now