Copying data from e-mail attachement to EXCEL file via macro

Status
Not open for further replies.
Correct. But the the files are .xlsx. The only difference I could find is that they are read only files.
 
Is the name of the effected files in upper cases? That makes a difference. Use the Lcase function to turn everything into lower cases.
 
That's not it unfortunately. The file is in lower cases. I tried the LCase function anyway but with no result. Really weird.
 
I'll test it - it should work though, since you are only reading it and using an outlook macro rather than excel. I'm not sure if i'll have a chance to test it today, but do have a couple of breaks. (I'm at a conference and don't have a full schedule today.)
 
If there´s an On Error Resume Next in the code, remove it.
 
There is no On Error Resume Next in the code.

@Diane I am using the code out of excel and not outlook, if that makes any difference.
 
If you set a breakpoint on the line with the message box, then place the mouse over the FileName property when the code execution stops , what does it display?
 
Sorry, I am not sure what you mean. I set a breakpoint on the line with the message box, ran the code and now the line is highlighted yellow. When I place the mouse over the line "oOlAtch.SaveAsFile AttachmentPath & NewFileName" a box pop ups with "attachement path= ...."
When I put the mouse above other lines nothing happens
 
When the code exec stops, look at the value in oOlAtch.Filename. It cannot end with ".xlsx" in lower cases else the msgbox wouldn´t be displayed.
 
When the code stops, nothing changes. The line still reads If Right$(oOlAtch.Filename, 5) = ".xlsx"
 
Sure. You need to look at the content of the oOlAtch.Filename property. One method to do so is to hover with the mouse over "FileName". That should display the prop´s content in a tooltip.
 
Sorry, but nothing happens when I hover with the mouse over FileName. Only when I hover over NewFileName. Here it says NewFileName= "CP1.xlsx"
 
That should mean oOlAtch is declared as object, not as attachment. You can also open the local window to look at a variable´s content. Or select all the "oOlAtch.Filename", then press shift+f9.
 
So I just checked and oOlAtch wasn't declared at all. But the code still works somehow. When I select oOlAtch.Filename and press F9 it says "Outside of Context" (rough translation as I don't use Excel in english).
 
You´re kidding, aren´t you? Of course, debugging only works when the code is running.
 
Sorry, your are right. I am new to VBA. Now it says value: image001.png

I tried declaring oOlAtch as Attachment but it doesn't work.
 
Great, now you see why the msgbox pops up, it´s because some emails have more than just the expected attachments. Your error is a logical one: You don´t know at which position the Excel attachment is, so you cannot display the "not found" message and leave the loop as soon as it hits a non Excel attachment because the Excel attachment you´re looking for could be at the next position.

If you need to ensure that only one attachment per email is saved, then leave the loop after the attachment has been saved. If it should be possible to save more than one attachment, then don´t leave the loop at all.
 
Okay, so is there a way that VBA checks both attachments and only downloads the .xlsx file? To be honest I though it was already doing exactly that.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
B Copying data between atbs in a custom form Outlook VBA and Custom Forms 4
N error when copying outlook data "can not copy: the path too deep" Using Outlook 6
R Copying Data from Exchange to PST file Outlook VBA and Custom Forms 1
H Copying email address(es) in body of email and pasting in To field Outlook VBA and Custom Forms 1
P Copying ALL calendar entries from Calender in PST file to IMAP OST file? Using Outlook 1
R VBA for copying sent email to current folder under a shared mailbox Outlook VBA and Custom Forms 17
E Copying the whole e-mail body into excel Outlook VBA and Custom Forms 0
T Copying Outlook Account Setup For Desktop App Using Outlook 5
J Outlook - 2013 - Error msg when copying folders from Online Archives to another user's mailbox Using Outlook 0
Thiago Manzano Copying E-mails to a folder on HD Using Outlook 1
Diane Poremsky Mark Sent Items as Read After Copying with a Rule Using Outlook 0
crazyboy Copying BCM database from backed up mounted image to new drive BCM (Business Contact Manager) 2
oliv- Prevent copying shared contacts Outlook VBA and Custom Forms 5
Paul Butticaz Copying Contacts from SharePoint List (connected to Outlook) to another Conacts folder Using Outlook 1
K Outlook 2010 Not responding after IMAP folder deletion or copying. Using Outlook 2
Mary B Outlook 2013: Rule for copying new email to folder & marking that copy as read Using Outlook 1
S Calendar items are not being uploaded to outlook.com after copying Using Outlook.com accounts in Outlook 1
P open reminders missing after copying outlook pst file Using Outlook 2
L Copying Emails using drag and drop Using Outlook 2
O New to Outlook 2013, dealing with copying vs. moving sent items Using Outlook 0
S Recover messages that disappeared when copying to folder Using Outlook 1
S Copying multiple messages to folders and keeping date/time detail Using Outlook 1
D Copying POP3 folders from Inbox to IMAP Inbox in Outlook 2003 Using Outlook 0
M Copying setups for mutiple users Using Outlook 2
T Location and simple copying of emails and settings, OL 2010 and Win 7 64bit. Using Outlook 3
A Copying additional contact fields when chosing "Contact from the same company" Using Outlook 5
A Copying cc email addresses to Excel - does not copy the <joe.bloggs@isp.com> Using Outlook 1
S Search Indexing (Copying Folders) Using Outlook 0
E Copying multiple folders to PST Outlook VBA and Custom Forms 2
R copying a custom view from a public folder and distributing programatically Outlook VBA and Custom Forms 3
N Copying outlook macros between pcs Outlook VBA and Custom Forms 1
V Copying contents from one field to another field Outlook VBA and Custom Forms 6
C Advanced search terms for "Outlook Data File" Using Outlook 1
C Populate form data into message body Outlook VBA and Custom Forms 1
CWM550 Saving Data: Don't check certain folders Using Outlook 2
CWM550 Importing " Old Skool" Data Using Outlook 0
W Create a Quick Step or VBA to SAVE AS PDF in G:|Data|Client File Outlook VBA and Custom Forms 1
Wotme create email only data file Using Outlook 1
V Backup Calendar, Contacts, Tasks in an POP3 data file Using Outlook 3
e_a_g_l_e_p_i Changing where data .pst is saved to Using Outlook 3
J Deliver new messages to New or Existing Data File? Using Outlook 2
G Outlook 2016: Want IMAP Data Files on My D: Drive and Not C: Drive Using Outlook 1
T vba extract data from msg file as attachment file of mail message Outlook VBA and Custom Forms 1
D Outlook 2016 Unable to load Outlook data pst file Using Outlook 5
V Form data not sending for some users Outlook VBA and Custom Forms 2
D Outlook VBA error extracting property data from GetRules collection Outlook VBA and Custom Forms 10
J Outlook 2013 Change color of text in data fields of contacts in Outlook 2013? Using Outlook 10
T How can Exchange be configured to sync/push one-way so that the server data can't be affected Exchange Server Administration 0
T Extract Data From Outlook Tasks Using Outlook 0
F outlook.com Exchane Server corrupts data Since September 2019 Using Outlook.com accounts in Outlook 6

Similar threads

Back
Top