Solved

How to declare a selection of email messages

Posted on 2008-06-12
1
256 Views
Last Modified: 2013-11-22



Hi
I have written a macro that saves an open email according to certain criteria when I hit a customised toolbar button.
I wish to modify this code such that it can act on a selection of emails within the inbox - ie needs to loop through the selected items.
I am unsure how to declare the 'selected items' andhow to handle them in a loop.
If someone could please write the lines to do this, I would really appreciate it.

cheers.
my current declarations are below, where objItem is the open email.


''''''''''
Sub save_multi_msgs()

'**********************************************************************************************************
' save_multi_msgs() macro performs the following tasks:
'**********************************************************************************************************
' - is run from a customised toolbar button in the outlook main window.
' - checks to see if there is a job number in the subject
'         - if there is no job number: -  prompts the user for one
'                                      -  renames emails that are not prefixed with their job number
' - if there is no subject, renames the email jobnumber_untitled
' - checks to see if the message has been saved already (if so, tells user and asks if they still want to save, or cancel)
' - checks to see that the filepath exists (if not, creates filepath after user prompt)
'**********************************************************************************************************

    Dim myItem As Outlook.Inspector
    Dim objItem As Object
    Set myOlApp = CreateObject("Outlook.Application")
    Set myItem = myOlApp.ActiveInspector
   
    If Not TypeName(myItem) = "Nothing" Then
        Set objItem = myItem.CurrentItem
        esubject = objItem
        'Prompt the user for confirmation
        Dim strPrompt As String
        Dim JNum As String
        Dim JNum_year As String
        Dim JNum_4 As String
        'Dim MyFolder As FileSystemObject
        Dim j As Integer
        Dim FileName As String
        Dim Timed As String
        ' restructure string name to get rid of formatting
            Dim senderName As String
        Dim senderaddr As String
        ' restructure string name to get rid of formatting
         senderaddr = objItem.SenderEmailAddress
         senderName = objItem.senderName
             Dim k As Integer
    Dim k1 As Integer
    Dim posn1(10) As String
    Dim Filepath1_folder(10) As String

' Executes code to save msg here.
' objItem is the open email.


del: objItem.Delete 'this line deletes the email from the inbox
fin:
End Sub
0
Comment
Question by:kafrin_1
1 Comment
 

Accepted Solution

by:
kafrin_1 earned 0 total points
Comment Utility
Got it:

added Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection

   Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection
Dim iSel As Long
iSel = myOlSel.Count
'for all items do...
For Each myItem In myOlSel

commented out  'Dim myItem As Outlook.Inspector
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Resolve DNS query failed errors for Exchange
Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

11 Experts available now in Live!

Get 1:1 Help Now