I know this is an Excel forum but ...

adambc

Active Member
Joined
Jan 13, 2020
Messages
412
Office Version
  1. 365
Platform
  1. Windows
Having failed in my attempt to move a VBA macro that uses Dir from a local/network drive environment to OneDrive, I’ve now built a solution that sends an Outlook email/attachment to the intended recipient, but they still have to save the attachment to the designated folder ...

So I’ve been looking at automatically saving the attachment when the new mail is received in Outlook ...

There are several posts in several forums that tell me how to do this, but I cannot get anything to work ...

I want to save the attachment that I KNOW will be named NEWINCIDENT??????.xlsm (where ?????? is a unique string) to a named folder ...

I'm running Office 365 Home/Outlook Version 2002 (Build 12527.20278 Click-to-Run) ...

This is "typical" of the VBA code I've put into ThisOutlookSession ...
Code:
Public WithEvents olItems As Outlook.Items

Private Sub Application_Startup()
Set olItems = Session.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub olItems_ItemAdd(ByVal Item As Object)
Dim NewMail As Outlook.MailItem
Dim Atts As Attachments
Dim Att As Attachment
Dim strPath As String
Dim strName As String

If Item.Class = olMail Then
Set NewMail = Item
End If

Set Atts = Item.Attachments

If Atts.Count > 0 Then
For Each Att In Atts
'neither of the following 2 lines work
If Att.FileName = "NEWINCIDENT*.*" Then
'If InStr(LCase(Att.FileName), "NEWINCIDENT") > 0 Then
strPath = "C:\Users\User\Documents\$$$ADAM\New_Incidents_Submitted"
strName = NewMail.Subject & " " & Chr(45) & " " & Att.FileName
Att.SaveAsFile strPath & strName
End If
Next
End If
End Sub
... and Saved/restarted Outlook ...

... but it doesn't seem to do anything (at least not what I want it to!) ...

Can anyone help please - or is there a forum as responsive as this one that has a similar focus on Outlook?

Many thanks ...
 
Last edited by a moderator:
Cannot test it, but I guess:
VBA Code:
Set olItems = Application.GetNamespace("MAPI").Folders("Name@Domain.xyz").Folders("Incoming emails").Items

Adapt of course the account string and the name of the Inbox folder to your context.

Bye
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

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