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
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"
Set mystartfolder = myfolder.Folders("Shipment Updates"
' 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"
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