Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I select a group of messages?

Status
Not open for further replies.

yakiyak

IS-IT--Management
Jun 10, 2003
5
US
I want to select a group of messages in the following code. I need to get replace the satement:
Set objSelection = objOL.ActiveExplorer.Selection

Because I don't want to go into Outlook each time to select messages in that folder. I need to select all the messages in that folder to process and need the code to do it automatically.

Thanks for your help!

Private Sub Move_Data_from_Outlook_Click()

Dim objOL As Outlook.Application
Dim objMsg As Object
Dim objAttachments As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim i As Long
Dim lngCount As Long
Dim strFile As String
Dim strFileArchive As String
Dim strFolder As String
Dim strArchive As String
Dim strObjFolder As Outlook.mapiFolder
Dim objNewMail As Message

Dim objMessages As Messages
Dim objMessage As Message

On Error Resume Next
Set objOL = CreateObject("Outlook.Application")
Set myNamespace = objOL.GetNamespace("MAPI")
Set myfolder = myNamespace.GetDefaultFolder(olFolderInbox)
Set myDestFolder = myfolder.Folders("Shipment Updates").Folders("Archive")
Set mystartfolder = myfolder.Folders("Shipment Updates").Folders("Automated Emails")

' reference the messages in Automated Emails folder
'Set objMessages = myStartFolder.Items

Set objSelection = objOL.ActiveExplorer.Selection
' Set objSelection = mystartfolder.GetExplorer.Items.Selection

strFolder = "C:\Documents and Settings\jdinh\My Documents\" & _
"Projects\Shared Files\Open PO Report\Shipment Status Download\"
strArchive = "C:\Documents and Settings\jdinh\My Documents\" & _
"Projects\Shared Files\Open PO Report\Shipment Status Download\" & _
"Archive\"

'For Each objMessage In objMessages
For Each objMsg In objSelection
If objMsg.Class = olMail Then
Set objAttachments = objMsg.Attachments
lngCount = objAttachments.Count
If lngCount > 0 Then
For i = lngCount To 1 Step -1
If objAttachments.Item(i).FileName = "manifest_all_delim_d.txt" Then
strFileArchive = strArchive & "Conway Manifest Updates " & _
Format(Now(), "yyyymmdd") & ".txt"
strFile = strFolder & "Conway Manifest Updates.txt"
' MsgBox "Finished Moving Conaway Data"
objAttachments.Item(i).SaveAsFile strFileArchive
objAttachments.Item(i).SaveAsFile strFile
Call mcr_import_conway_Click

Else
strFileArchive = strArchive & objAttachments.Item(i).FileName
strFile = strFolder & "Current Yellow Updates.txt"
objAttachments.Item(i).SaveAsFile strFileArchive
objAttachments.Item(i).SaveAsFile strFile
' MsgBox "Finished Moving Yellow Data"
Call mcr_import_yellow_Click
End If
'objAttachments.Item(i).SaveAsFile strFileArchive
'objAttachments.Item(i).SaveAsFile strFile
Next i
End If
objMsg.Move myDestFolder
End If
Next
MsgBox "Import Complete"
ExitSub:
Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub
 
Without trawling through all your code, which basically looks the same as mine, here are a couple of snippets that may help. This picks up all mail from my inbox :-

'------------------------------------------------
Public MyMailItem As Object
'------------------------------------------------------
MailBoxName = "Mailbox - " & MyName
Set MyMailFolder = MyNamespace.folders(MailBoxName).folders("Inbox")
For i = 1 To MyMailFolder.Items.Count
Set MyMailItem = MyMailFolder.Items(i)
MailDate = Format(DateValue(MyMailItem.creationtime), "dd/mm/yyyy")
MailSender = MyMailItem.SenderName
MailSubject = MyMailItem.Subject
MailListItems = MailListItems + 1
'-
MailList(i, 1) = MailDate
MailList(i, 2) = MailSender
MailList(i, 3) = MailSubject
MailList(i, 4) = i
Next
'-----------------------------------------------------------


Regards
BrianB
** Let us know if you get something that works !
================================
 
Thanks for the response. I tried it and somehow the count is messed up because after I read the first item, I move it to another folder. Does that change the item count each time it runs through the loop? How do I code it so that it will select all items in the folder and return an object with all the items. for instance, is there a
MyFolder.SelectAllMailItems statement or something? I tried looking for it but was unsuccessful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top