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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

757 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