Setting a variable array in a objMsg loop?

Stildawn

Board Regular
Joined
Aug 26, 2012
Messages
201
Hi All

Sorry other question, I have this code:

Code:
Set objOL = CreateObject("Outlook.Application")Set objSelection = objOL.ActiveExplorer.Selection

For Each objMsg In objSelection
    ans = MsgBox("Sender: " & objMsg.SenderName & vbNewLine & "Subject: " & objMsg.Subject & vbNewLine & "Received: " & objMsg.ReceivedTime & "                         ", vbYesNo, "Do you want to send this entire email?")
    If ans = vbYes Then
            mailfile = objMsg.SenderName & ".msg"
            objMsg.SaveAs strFolderpath & mailfile, olMSG
        Else
            Set objAttachments = objMsg.Attachments
            lngCount = objAttachments.Count
            If lngCount > 0 Then
                For i = lngCount To 1 Step -1
                    strFile = objAttachments.Item(i).FileName
                    strFile = strFolderpath & strFile
                    objAttachments.Item(i).SaveAsFile strFile
                Next i
            End If
    End If
Next

This code takes the highlighted emails in a users Outlook, and asks them if they want to send the whole email or not. If they hit YES then the entire email is saved to a directory, if they hit NO then just the attachments of that email is saved to the same directory... It then asks the same question on the next email in their highlighted selection.

This works perfectly as planned. But further along I am building in some cancel features... And my question is, how can I save each *.msg file saved full path and each attachments full path into their own variable?

The plan is that if each time Outlooks saves (either a .msg or an attachment) it saves the full path into a variable, which later on down the code if the user hits cancel... Then I can run some "Kill" commands to delete all the files that were saved down.

I think I can code this myself using: "Dim emailarray(1 To objSelection.Count) As Integer" & "Dim filearray(1 To lngCount) As Integer"

But that would require scrapping the "For Each objMsg In objSelection" loop for a "For e = 1 to objSelection.Count" loop working with objMsg? But I don't know how to do that?

If you have any ideas or other solutions would be greatly appreciated.

Thanks
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,225,651
Messages
6,186,185
Members
453,339
Latest member
Stu61

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top