dwilson38550m
Board Regular
- Joined
- Nov 21, 2005
- Messages
- 89
Hi,
I am going crazy trying to get this to work. I wonder if someone could give me some help. Every day I receive a file statement from the bank showing daily bank balances - I have created a rule in MS Outlook (2016) to move these emails containing an attachment to a folder called HSBC. I would like to use VBA in Excel to automatically extract the file attachments and save these to a specific folder C:\Users\david.wilson\Desktop\HSBC. The files will
- always have IntradayStatement in the filename;
- the email will always come from the sender address which has HSBCnet in email address and
- the subject will always be HSBCnet Automated File Delivery.
I want to save the file attached with the filename "HSBCdownload.xls" to C:\Users\david.wilson\Desktop\HSBC which I have specified on cell A3 of the current workbook (the idea is that the files downloaded daily will overwrite the existing files in this folder)...so I always see the most current version.
I have attached the code I have created so far but this doesn't seem to work - is there anything anyone can suggest? Thanks in advance.
-----------------------------------------------------------------------------------------------------------------------------------------
Option Explicit
' early binding
Sub outlook_email_save()
Dim olook As Outlook.Application
Set olook = New Outlook.Application
Dim omail As Outlook.MailItem
Set omail = olook.CreateItem(olMailItem)
Dim ospace As Outlook.Namespace
Set ospace = olook.GetNamespace("MAPI")
Dim myfol As Outlook.Folder
Set myfol = ospace.GetDefaultFolder(olFolderInbox).Folders("HSBC")
Dim atmt As Attachment
For Each omail In myfol.Items
If omail.Subject Like "HSBCnet Automated" Then
For Each atmt In omail.Attachments
If atmt.Filename Like "*" & "IntradayStatement" Then
atmt.SaveAsFile Range("A3").Value & atmt.Filename
Else
'do nothing
End If
Next
Else
'do nothing
End If
Next
End Sub
Thanks in advance.
I am going crazy trying to get this to work. I wonder if someone could give me some help. Every day I receive a file statement from the bank showing daily bank balances - I have created a rule in MS Outlook (2016) to move these emails containing an attachment to a folder called HSBC. I would like to use VBA in Excel to automatically extract the file attachments and save these to a specific folder C:\Users\david.wilson\Desktop\HSBC. The files will
- always have IntradayStatement in the filename;
- the email will always come from the sender address which has HSBCnet in email address and
- the subject will always be HSBCnet Automated File Delivery.
I want to save the file attached with the filename "HSBCdownload.xls" to C:\Users\david.wilson\Desktop\HSBC which I have specified on cell A3 of the current workbook (the idea is that the files downloaded daily will overwrite the existing files in this folder)...so I always see the most current version.
I have attached the code I have created so far but this doesn't seem to work - is there anything anyone can suggest? Thanks in advance.
-----------------------------------------------------------------------------------------------------------------------------------------
Option Explicit
' early binding
Sub outlook_email_save()
Dim olook As Outlook.Application
Set olook = New Outlook.Application
Dim omail As Outlook.MailItem
Set omail = olook.CreateItem(olMailItem)
Dim ospace As Outlook.Namespace
Set ospace = olook.GetNamespace("MAPI")
Dim myfol As Outlook.Folder
Set myfol = ospace.GetDefaultFolder(olFolderInbox).Folders("HSBC")
Dim atmt As Attachment
For Each omail In myfol.Items
If omail.Subject Like "HSBCnet Automated" Then
For Each atmt In omail.Attachments
If atmt.Filename Like "*" & "IntradayStatement" Then
atmt.SaveAsFile Range("A3").Value & atmt.Filename
Else
'do nothing
End If
Next
Else
'do nothing
End If
Next
End Sub
Thanks in advance.