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

asked on

Working from Word or Access, I am looking for code to prompt the user for the name of an outlook folder

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

I would 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)
                .SentOnBehalfOfName = 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

Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Try:

    Set fldr = olkapp.Session.PickFolder

Chris
Avatar of rogerdjr

ASKER

Folder picker provides the prompt to pick a folder, works great

But I'm not sure how to incorporate into the code above to have it edit the emails in the folder selected from the picker

Thanks
For Each mai In olkApp.Session.pickfolder.items
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
Works Perfect Thanks