Link to home
Start Free TrialLog in
Avatar of rogerdjr
rogerdjrFlag for United States of America

asked on

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

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
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

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
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have just tested getaccounts and it works fine so should do as required ... in the case of 2007 and later

Chris
Avatar of rogerdjr

ASKER

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
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