Solved

How to declare a selection of email messages

Posted on 2008-06-12
1
283 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
ID: 21774634
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

If you thought ransomware was bad, think again! Doxware has the potential to be even more damaging.
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: …

860 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