Solved

How to declare a selection of email messages

Posted on 2008-06-12
1
300 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Threat Trends for MSPs to Watch

See the findings.
Despite its humble beginnings, phishing has come a long way since those first crudely constructed emails. Today, phishing sites can appear and disappear in the length of a coffee break, and it takes more than a little know-how to keep your clients secure.

Question has a verified solution.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
Changing a few Outlook Options can help keep you organized!
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

691 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