Solved

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

Posted on 2011-09-22
6
223 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:rogerdjr
  • 3
  • 2
6 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 36588083
Try:

    Set fldr = olkapp.Session.PickFolder

Chris
0
 

Author Comment

by:rogerdjr
ID: 36588447
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
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 36589683
For Each mai In olkApp.Session.pickfolder.items
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 36589701
Allowing for operator cancel on the selection then ...

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

    acct = getAccount
    If acct = 0 Then acct = 1
    Set olkApp = CreateObject("outlook.application")
    Set fldr = olkApp.Session.PickFolder
    If fldr Is Nothing Then Exit Sub
    For Each mai In fldr.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

Open in new window

0
 

Author Closing Comment

by:rogerdjr
ID: 36590406
Works Perfect Thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
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…
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

840 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