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

asked on

VBA code fails to change the "Sent" address

I posted this question ( http:/Q_27314268.html ) and got a great response that works fine from outlook.

I believe this "follow-on" would qualify as a new question.

When I try to run the code provided from Word or Access, the code adds the attachment, sets the reminder flag, sets the read and receipt notification. But it does not change the "Sent" address.

Attached is the code from my application in Word (imported directly from the previous response).

I would also like the code to prompt the user for the name of the folder (possibly offer a list of folders for the user to choose from) if possible.

I would appreciate any help you can offer
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 "e:\0\Access - (001) 042307.ADA Fee Proposal.pdf", 5
                .SendUsingAccount = olkApp.Session.Accounts.Item(acct)
' Need to establish the account required ... but once set can be hard coded.
                .Send
                MsgBox acct & vbNewLine & olkApp.Session.Accounts.Item(acct)
            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

ASKER CERTIFIED SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America 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
Selecting a folder should be a separate question as it is totally separate form your main question here...
as it requires a bit more of an explanation of how it will be used and your current configurations, settings, versions, ...etc
Avatar of rogerdjr

ASKER

.SendOnBehalfOf - works great

.SendAs - causes an error

Thanks