?
Solved

How to declare a selection of email messages

Posted on 2008-06-12
1
Medium Priority
?
303 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

When ransomware hits your clients, what do you do?

MSPs: Endpoint security isn’t enough to prevent ransomware.
As the impact and severity of crypto ransomware attacks has grown, Webroot fought back, not just by building a next-gen endpoint solution capable of preventing ransomware attacks but also by being a thought leader.

Question has a verified solution.

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

How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
Curious about the latest ransomware attack? Check out our timeline of events surrounding the spread of this new virus along with tips on how to mitigate the damage.
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…
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…
Suggested Courses

801 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