Hi! I'm having a bug when I want to test it in Immediate (min: 3:55) the error appears to be in Set fol = ns.Folders(1).Folders("Foldername") Do you know what could be it?
This video is the only thing that actually helped me save all attachments, every other tutorial on the web is kinda whack... couldnt get them to work. This vid is perfect. I also like that you actually explain the code as you write it.
Hi Andrew, How we can download the attachment from the particular email or specific time period. for example: Someone share the excel files from last 2 month, and i want to save all the attachment of that specific email id for only last month. It can be possible. if Yes please help us.
Andrew great video, even I could get it to work! I do have one question. Is there a way for the macro to run automatically with Outlook open? What code do I need to add so I don’t have to run the macro...... Thanks!
thanks for this it was really helpful. Can I point this to a windows folder where the outlook items are located instead of outlook itself? I receive an email with a zipfile attached. I have to unzip the contents of that file which has 30 days worth of emails each with an attachment. I can copy and paste them back in an outlook folder and run this but ideally would like to be able to run it against the windows folder. Thanks
Hi Chris! Yes, you can loop through email items stored in a Windows folder. There are several ways to do this, here's a simple one using the Dir function. It assumes that you have a folder called Emails containing the saved messages and a folder called Attachments in the same folder as the Excel file which contains your VBA code: Sub SaveAttachmentsFromFileSystem() Dim AttachmentsFolder As String Dim EmailFolder As String Dim EmailPath As String Dim olk As Outlook.Application Dim mi As Outlook.MailItem Dim at As Outlook.Attachment EmailFolder = ThisWorkbook.Path & "\Emails\" EmailPath = Dir(EmailFolder & "*.msg") If EmailPath = "" Then Exit Sub AttachmentsFolder = ThisWorkbook.Path & "\Attachments\" Set olk = New Outlook.Application Do Debug.Print EmailPath Set mi = olk.CreateItemFromTemplate(EmailFolder & EmailPath) mi.Display For Each at In mi.Attachments Debug.Print at.Filename at.SaveAsFile AttachmentsFolder & at.Filename Next at mi.Close olDiscard EmailPath = Dir Loop Until EmailPath = "" End Sub
Hello! Video 29.6 in this playlist explains how to reference a specific Outlook folder ruclips.net/p/PLNIs-AWhQzcleylKSN4MS-tJloReq0XcK When you loop through attachments you can test if the final four characters of the FileName property equals "xlsx" to determine if it's an Excel file (adjust for xlsm or xlsb files) If LCase(Right(atc.FileName, 4)) = "xlsx" Then
Hi there! I follow th macro but when i try to access to my Inbox sub folder "Test" i don't get to it - i receive Run-time error - 2147221233 The attempted operation failed. An object could not be found. But my sub folder Test is there. How can i avoid that error?
Hi Ken! Did you mean you wanted the code shown in the video? If so you can find a link in the video description to download the completed file. I hope it helps and thanks for watching!
Hi Mohan! It depends on how you're identifying the specific email - you could use filters with the Find or Restrict methods to do this as described in videos 29.9 and 29.13 in this playlist ruclips.net/p/PLNIs-AWhQzcleylKSN4MS-tJloReq0XcK I hope that helps!
It looks like my Outlook is set to store emails on the server side after a year. Even though I can see the emails in the application, VBA can't find them. Is there a means access server-side emails using VBA?
Hi! I'm not sure there's a way to do this but these links might help (the second one is for VB.NET but describes the same problem): stackoverflow.com/questions/26731604/vba-not-all-outlook-emails-show-up stackoverflow.com/questions/59537648/get-all-outlook-emails-including-ones-on-server
Hello, Andrew! Amazing job! Is there a way to unzip a file using VBA? Everyday, I receive a zip file in the Outlook. So, I need to unpack it manually to a folder and after that I use a VBA routine to manipulate the data. I would like to automatize the whole process. Can you help me? Thanks a lot for share your knowleadge.
Thanks Marcelo! Here's the basic code to unzip a folder into a separate existing folder: Dim sh As Object Set sh = CreateObject("Shell.Application") sh.Namespace(ThisWorkbook.Path & "\Unzipped Files").CopyHere _ sh.Namespace(ThisWorkbook.Path & "\Zipped Files.zip").Items And if you'd like to know what it all means, watch out for a video appearing soon!
Hi! You can use the Replace function to do this docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/replace-function I hope it helps!
Hi Alex! You can use the InStr function docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/instr-function or the Like operator docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/like-operator to check if the attachment name contains a particular string. I hope that helps!
Hi Mark, we have another video which explains how to reference other accounts ruclips.net/video/zgTqzDQ8VqI/видео.html I hope it helps and thanks for watching!
These videos are amazing! Thank you for sharing your knowledge. One question I have is will this code, when ran every time, re-save old files and cause duplicates? If so if there a line of code to insert that will pull all files once and then only pull the latest email received?
Hi Joe, check that you have a Dim statement for the ns variable and that you've spelt it correctly (that sounds patronising but I've lost count of how many times I've misspelt a simple variable name and seen this compile error!)
Dear Sir, I had a query regarding VBA Code Attaching Active Excel workbook in outlook Sir I made a VBA Program where i copy and paste data in new workbook now i want to attached this new workbook in outlook file using "Application.Dialogs(xlDialogSendMail).Show" this Technique. Now when i run this macro in Step Into mode[F8] its working fine but when i run same macro Run mode(F5/Green Triangle Button) taking lots of time and showig this errors messages "cannot find this file verify the path and file name are correct". So Sir Please Help me on this matter. Sir if possible please Make vedio on this Topic (Application.Dialogs(xlDialogSendMail).Show)
I get an error " you dont have appropriate permission to perform this operation" when i try to save the attachment in my local folder. how do i tackle this?
Hi Priyanka, it seems that this can be caused by a variety of reasons. My suggestion would be to rely on Google (something like "outlook attachment appropriate permission to perform this operation" will do) and work your way through the suggested solutions
How can this be automated when receiving a new email with an attachment in a subfolder I specify ? It works great when I run it manually but I can't get it to run when I receive a new email with an attachment. Thanks in advance!!! Your videos are awesome!!!
Hi Mark! You can use the NewMail event of the Outlook application to trigger code when mail is received docs.microsoft.com/en-us/office/vba/api/outlook.application.newmail I hope it helps!
Great video. Nice clear instructions. Thank you! I followed them very carefully and I'm getting "An object could not be found" Run-time error on the Set fol = ns.Folders(1).Folders("David") line. I did add the reference to the Microsoft Outlook and double checked it. I checked the folder name. What could be the problem? Option Explicit Sub SaveOutlookAttachements() Dim ol As Outlook.Application Dim ns As Outlook.Namespace Dim fol As Outlook.Folder Dim i As Object Dim mi As Outlook.MailItem Set ol = New Outlook.Application Set ns = ol.GetNamespace("MAPI") Set fol = ns.Folders(1).Folders("David") For Each i In fol.Items If i.Class = olMail Then Set mi = i Debug.Print mi.SenderName, mi.ReceivedTime End If
@@WiseOwlTutorials Thank you. I'll try that. I did think of that, but it looked like your "Dell" folder was a subfolder also, so I didn't think it would matter. My "David" folder is only a subfolder of "Inbox." Is that considered the root level?
Well, I guess our organization is kind of odd. This is what worked for my Outlook folder structure: Set fol = ns.Folders(2).Folders("Inbox").Folders("David") Yeah, Folders(2) This video was extremely helpful. Thanks for the link to it. ruclips.net/video/tKNYgF2AKu0/видео.html Thank you again for the great videos!
Also to bring to your notice that this issue occurs only when I reboot my system and launch outlook again after a system reboot. Also i tried something new. When I rebooted my system this time I knew I would get the error again and so I did as expected..but in order to fix it all I did was to enter '2' in Folders (1) instead of '1'...and it worked...to be sure I restarted my system again with '2' in place this time...and I got the same error...so this time in order to fix it i replaced '2' back with '1' and it worked like a charm again... My new question after this tiny experiment is...why can't we simply set a presidency for the non-default folder once and for all rather than its presidency switching back and forth between 1 and 2...who knows after the next reboot I might have to use '3' 🙄
Guessing there has to be an easy solution, but I can't figure out what I would need to add if I just wanted to save files that have some unique criteria in the file name. So in this section I want to add what I have in parenthesis in the first line, but I can't figure out how to translate this into VBA. For Each at In mi.Attachments (That includes "Calls and Transfers in at.Filename)
Hi Ali, another viewer reported that using ns.Folders(2).Folders("Inbox").Folders("Dell") was required to locate the correct folder for him. You might find this video useful ruclips.net/video/tKNYgF2AKu0/видео.html I hope it helps!
Thank you very much sir🙏🏻I’ve learned a lot...could you please help to make a video for PDF macros using VBA (pull specific data from pdf and paste into excel)
What a cracking set of videos! Thank you so much for this Andrew! I am trying to amend code so it only downloads attachments AFTER 05/09/21 and the file size is over 15KB. When I run the routine the date aspects appears to work but the file cap is ignored. Could someone please help? Is it best to filter via "IF" or restrict method or a combo of both. Thanks so much. Option Explicit Sub SaveOutlookAttachments()
Dim olApp As Outlook.Application Dim olNS As Outlook.Namespace Dim olFolder As Outlook.Folder Dim olItem As Object Dim mi As Outlook.MailItem Dim olAtt As Outlook.Attachment Dim filterstring As String
Set olApp = New Outlook.Application Set olNS = olApp.GetNamespace("MAPI") Set olFolder = olNS.PickFolder
For Each olItem In olFolder.Items
If olItem.Class = olMail Then
Set mi = olItem
If mi.Attachments.Count > 0 And mi.ReceivedTime > "5 / 9 / 2021" And mi.Size > 15000 Then Debug.Print mi.SenderName, mi.ReceivedTime, mi.Attachments.Count, mi.Size
Hi Gillian, the test for size of the mail item looks fine and should work - it does for me. Bear in mind that the Size property of the mail item represents the full size of the entire email. If you want to check the size of each attachment separately, test the Size property of your olAtt variable in the second loop. I hope it helps!
@@WiseOwlTutorials Thanks so much for getting back to me. When I run the routine based on current parameters, I still pick up 5KB PNG files which is wrong. I have tried to add "For Each olAtt In mi.Attachments.Restrict(Filterstring)" But I do not have the intellisense drop-down option in the second loop? I have added Filterstring as a variable, and although it is not included in the earlier code, I would add FilterString = "[size] > 15000 AND [receivedtime] > '05/09/2021'" just above the first "For Each" loop. Would love your help on this.
@@gillianmcnosehair9097 You can't apply the Restrict method to the object returned by the Attachments property. Just loop through the attachments as you showed in the original code you posted. Add an If statement inside this loop which tests the olAtt.Size property, not the mi.Size property. I hope it helps!
@@WiseOwlTutorials Top, Top man. Thanks so much, Andrew. I added the following code: "For Each olAtt In mi.Attachments If olAtt.Size > 10000 And mi.ReceivedTime > "5/09/2021" Then" and it recognised the "IF" and executed perfectly. I've been toiling for an answer for weeks! Just stumbled upon your content and I've acquired a mass of knowledge from your excellent videos. I would like to thank you for making them available.
I am having an issue when I loop through a folder (for each i in fol.items), only about half of the emails are being picked up by the macro. I've tried setting fol.items to an Outlook.Items object and sorting, but still no good. Do you have any idea what could be happening here?
Hello, I get a runtime error 76, Path not found at line "Set dir = fso.CreateFolder(dirName)". I could retrieve and save the attachments so everything was running fine until I got to the stage of creating folders for the attachments. Any idea what caused the error?
Hi Alexandre! There are a couple of possible reasons for this. One is that you haven't created all of the necessary parent folders - the CreateFolder method can only create one level at a time. Another possibility is a simple spelling error in the folder path of the value in your dirName variable. I hope that helps!
Hi! I'm having a bug when I want to test it in Immediate (min: 3:55) the error appears to be in Set fol = ns.Folders(1).Folders("Foldername")
Do you know what could be it?
Could you find a solution to that? @wiseowltutorials
Wow. Awesome! Extremely valuable
Thanks for watching, David!
Very clear explanations. Worthy informations. Great job.Thank you so much.
Thank you Bilgehan!
Thank you so much sir for giving us such a valuable knowledge without any charges with the help of you we can boost our career and knowledge too🙏🙏🙏🙏🇮🇳
You’re my favourite sir
This video is the only thing that actually helped me save all attachments, every other tutorial on the web is kinda whack... couldnt get them to work. This vid is perfect.
I also like that you actually explain the code as you write it.
Glad you found what you were looking for, thanks for watching!
Brilliant and highly relevant to our regular work! Thank you!
Hi Andrew, How we can download the attachment from the particular email or specific time period. for example: Someone share the excel files from last 2 month, and i want to save all the attachment of that specific email id for only last month. It can be possible. if Yes please help us.
Sir, thank you a lot for this great video!
This was super helpful. Thanks!
Cheers Jeff, happy to hear it helped!
Andrew great video, even I could get it to work! I do have one question. Is there a way for the macro to run automatically with Outlook open? What code do I need to add so I don’t have to run the macro......
Thanks!
you are excelent! watching from KENYA
I need to save specific files (excel,word,pdf etc) to specific desktop folder specific subject line using macro code
Hi, i tried and I'm getting an error stating object could not be found for Folders which I set also the folder is available on outlook
When I run it its gets stopped on the folder step. any idea Set fol = ns.Folders(1).Folders("Scans")
thanks for this it was really helpful. Can I point this to a windows folder where the outlook items are located instead of outlook itself? I receive an email with a zipfile attached. I have to unzip the contents of that file which has 30 days worth of emails each with an attachment. I can copy and paste them back in an outlook folder and run this but ideally would like to be able to run it against the windows folder. Thanks
Hi Chris! Yes, you can loop through email items stored in a Windows folder. There are several ways to do this, here's a simple one using the Dir function. It assumes that you have a folder called Emails containing the saved messages and a folder called Attachments in the same folder as the Excel file which contains your VBA code:
Sub SaveAttachmentsFromFileSystem()
Dim AttachmentsFolder As String
Dim EmailFolder As String
Dim EmailPath As String
Dim olk As Outlook.Application
Dim mi As Outlook.MailItem
Dim at As Outlook.Attachment
EmailFolder = ThisWorkbook.Path & "\Emails\"
EmailPath = Dir(EmailFolder & "*.msg")
If EmailPath = "" Then Exit Sub
AttachmentsFolder = ThisWorkbook.Path & "\Attachments\"
Set olk = New Outlook.Application
Do
Debug.Print EmailPath
Set mi = olk.CreateItemFromTemplate(EmailFolder & EmailPath)
mi.Display
For Each at In mi.Attachments
Debug.Print at.Filename
at.SaveAsFile AttachmentsFolder & at.Filename
Next at
mi.Close olDiscard
EmailPath = Dir
Loop Until EmailPath = ""
End Sub
@@WiseOwlTutorials thanks so much, you are a gentleman and a scholar, a tea and biccie donation coming your way :-)
this works great
can someone tell me how to do this for a specific outlook subfolder
and
for only excel attachments
thanks
Hello! Video 29.6 in this playlist explains how to reference a specific Outlook folder ruclips.net/p/PLNIs-AWhQzcleylKSN4MS-tJloReq0XcK
When you loop through attachments you can test if the final four characters of the FileName property equals "xlsx" to determine if it's an Excel file (adjust for xlsm or xlsb files)
If LCase(Right(atc.FileName, 4)) = "xlsx" Then
@@WiseOwlTutorials thanks
@@murphy2870 You're welcome, thanks for watching!
Hi there! I follow th macro but when i try to access to my Inbox sub folder "Test" i don't get to it - i receive Run-time error - 2147221233 The attempted operation failed. An object could not be found. But my sub folder Test is there. How can i avoid that error?
i am getting error the operation failed. An object could not be found
Thank you so much Andrew
You're very welcome Aba, thank you for watching!
Hi, need your help
Can we use macro in shared mail box
Hi, yes you can docs.microsoft.com/en-us/previous-versions/office/developer/office-2003/aa220116(v=office.11)
I hope it helps!
Thanks for sharing.
How to download only top 50 mail please suggest..
Hi there, here's one solution stackoverflow.com/questions/52927919/top-50-emails-from-outlook-from-new-to-old
I hope it helps!
@@WiseOwlTutorials Thank you very much.
@@travllingisfun6189 No problem!
Hi Andrew do you have the script for saving attachment and renaming it based on the subject of email?
Hi Ken! Did you mean you wanted the code shown in the video? If so you can find a link in the video description to download the completed file. I hope it helps and thanks for watching!
Hi Andrew, really useful video. Is there a line of code that I could to select attachments from emails sent on a certain date?
Hello. How can we save attachmnets for specific email only rather than all mails from folder
Hi Mohan! It depends on how you're identifying the specific email - you could use filters with the Find or Restrict methods to do this as described in videos 29.9 and 29.13 in this playlist ruclips.net/p/PLNIs-AWhQzcleylKSN4MS-tJloReq0XcK
I hope that helps!
It looks like my Outlook is set to store emails on the server side after a year.
Even though I can see the emails in the application, VBA can't find them.
Is there a means access server-side emails using VBA?
Hi! I'm not sure there's a way to do this but these links might help (the second one is for VB.NET but describes the same problem):
stackoverflow.com/questions/26731604/vba-not-all-outlook-emails-show-up
stackoverflow.com/questions/59537648/get-all-outlook-emails-including-ones-on-server
Hello, Andrew! Amazing job! Is there a way to unzip a file using VBA? Everyday, I receive a zip file in the Outlook. So, I need to unpack it manually to a folder and after that I use a VBA routine to manipulate the data. I would like to automatize the whole process. Can you help me? Thanks a lot for share your knowleadge.
Thanks Marcelo! Here's the basic code to unzip a folder into a separate existing folder:
Dim sh As Object
Set sh = CreateObject("Shell.Application")
sh.Namespace(ThisWorkbook.Path & "\Unzipped Files").CopyHere _
sh.Namespace(ThisWorkbook.Path & "\Zipped Files.zip").Items
And if you'd like to know what it all means, watch out for a video appearing soon!
Code for collecting attachment from same subject mails..??
hi there, thank you so much for the knowledge. Is there a way we can replace special characters in the email subject, such as (*/>,
Hi! You can use the Replace function to do this docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/replace-function
I hope it helps!
Hello, can you please tell ne how to download only e-mail, which have the word "gesamt" in the attachment name ? Thank you:)
Hi Alex! You can use the InStr function docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/instr-function or the Like operator docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/like-operator to check if the attachment name contains a particular string. I hope that helps!
what if i want to get the folder a from a different mailer account, ? thank you for this tutorials!
Hi Mark, we have another video which explains how to reference other accounts ruclips.net/video/zgTqzDQ8VqI/видео.html
I hope it helps and thanks for watching!
@@WiseOwlTutorials wow thank you so much!
@@markvalenzuela7010 No problem!
You are awesome. Thank you so much for these videos.
These videos are amazing! Thank you for sharing your knowledge. One question I have is will this code, when ran every time, re-save old files and cause duplicates? If so if there a line of code to insert that will pull all files once and then only pull the latest email received?
Hi sir thank you so much can you give us same code in early binding method please
Getname space ("mapi") What is mapi i can't find previous definition of this please help
Hi! MAPI is WIndows' Messaging API en.wikipedia.org/wiki/MAPI
I hope it helps!
Hi Andrew,
Thank you so much for the tutorial, now I have the idea that how can I play with the attachments.
Thanks once again.
Thanks
Kashif
Where is the outlook folder saved ? I receive an object not found error on the set Folder line.
I get a complier error saying ns variable not defined
Hi Joe, check that you have a Dim statement for the ns variable and that you've spelt it correctly (that sounds patronising but I've lost count of how many times I've misspelt a simple variable name and seen this compile error!)
how can i just pull the most recent email in folder
Hi Jansen, the answer here might help www.mrexcel.com/board/threads/get-only-the-latest-email-in-outlook-and-copy-to-excel.1088004/
You have an amazing channel... thank u for sharing
Dear Sir,
I had a query regarding VBA Code Attaching Active Excel workbook in outlook Sir I made a VBA Program where i copy and paste data in new workbook now i want to attached this new workbook in outlook file using "Application.Dialogs(xlDialogSendMail).Show" this Technique. Now when i run this macro in Step Into mode[F8] its working fine but when i run same macro Run mode(F5/Green Triangle Button) taking lots of time and showig this errors messages "cannot find this file verify the path and file name are correct". So Sir Please Help me on this matter.
Sir if possible please Make vedio on this Topic (Application.Dialogs(xlDialogSendMail).Show)
I get an error " you dont have appropriate permission to perform this operation" when i try to save the attachment in my local folder. how do i tackle this?
Hi Priyanka, it seems that this can be caused by a variety of reasons. My suggestion would be to rely on Google (something like "outlook attachment appropriate permission to perform this operation" will do) and work your way through the suggested solutions
Superb video! Thank you!
How can this be automated when receiving a new email with an attachment in a subfolder I specify ? It works great when I run it manually but I can't get it to run when I receive a new email with an attachment. Thanks in advance!!! Your videos are awesome!!!
Hi Mark! You can use the NewMail event of the Outlook application to trigger code when mail is received docs.microsoft.com/en-us/office/vba/api/outlook.application.newmail
I hope it helps!
@@WiseOwlTutorials Thank you so much!!!!
@@markmiller4659 You're very welcome!
Great video. Nice clear instructions.
Thank you!
I followed them very carefully and I'm getting "An object could not be found" Run-time error on the Set fol = ns.Folders(1).Folders("David") line.
I did add the reference to the Microsoft Outlook and double checked it.
I checked the folder name.
What could be the problem?
Option Explicit
Sub SaveOutlookAttachements()
Dim ol As Outlook.Application
Dim ns As Outlook.Namespace
Dim fol As Outlook.Folder
Dim i As Object
Dim mi As Outlook.MailItem
Set ol = New Outlook.Application
Set ns = ol.GetNamespace("MAPI")
Set fol = ns.Folders(1).Folders("David")
For Each i In fol.Items
If i.Class = olMail Then
Set mi = i
Debug.Print mi.SenderName, mi.ReceivedTime
End If
Next i
End Sub
@@WiseOwlTutorials Thank you. I'll try that. I did think of that, but it looked like your "Dell" folder was a subfolder also, so I didn't think it would matter.
My "David" folder is only a subfolder of "Inbox." Is that considered the root level?
I'll try .Folders("Inbox").Folders("David")
That did not work either. Nor did just .Folders("Inbox") I'll refer to the other videos you linked.
Well, I guess our organization is kind of odd. This is what worked for my Outlook folder structure:
Set fol = ns.Folders(2).Folders("Inbox").Folders("David")
Yeah, Folders(2)
This video was extremely helpful. Thanks for the link to it.
ruclips.net/video/tKNYgF2AKu0/видео.html
Thank you again for the great videos!
Thanks Andrew, great stuff
Set fol = ns.Folders(1).Folders("Clic Raw")
Gives an error "object not found", once the system restarts. Why ?
Also to bring to your notice that this issue occurs only when I reboot my system and launch outlook again after a system reboot.
Also i tried something new. When I rebooted my system this time I knew I would get the error again and so I did as expected..but in order to fix it all I did was to enter '2' in Folders (1) instead of '1'...and it worked...to be sure I restarted my system again with '2' in place this time...and I got the same error...so this time in order to fix it i replaced '2' back with '1' and it worked like a charm again...
My new question after this tiny experiment is...why can't we simply set a presidency for the non-default folder once and for all rather than its presidency switching back and forth
between 1 and 2...who knows after the next reboot I might have to use '3' 🙄
Guessing there has to be an easy solution, but I can't figure out what I would need to add if I just wanted to save files that have some unique criteria in the file name.
So in this section I want to add what I have in parenthesis in the first line, but I can't figure out how to translate this into VBA.
For Each at In mi.Attachments
(That includes "Calls and Transfers in at.Filename)
'Debug.Print vbTab, at.DisplayName, at.FileName, at.Size
at.SaveAsFile "Y:\STATS\Processing\" & Format(mi.ReceivedTime, "yyyy-mm-dd hh-nn-ss ") & at.FileName
i got an error on the set fol line, i have no idea why?
Hi Ali, another viewer reported that using ns.Folders(2).Folders("Inbox").Folders("Dell") was required to locate the correct folder for him. You might find this video useful ruclips.net/video/tKNYgF2AKu0/видео.html
I hope it helps!
Thank you very much sir🙏🏻I’ve learned a lot...could you please help to make a video for PDF macros using VBA (pull specific data from pdf and paste into excel)
WiseOwlTutorials Thank you very much sir🤝...I will go through the above link now...however you will post a video for upcoming season.
What a cracking set of videos! Thank you so much for this Andrew!
I am trying to amend code so it only downloads attachments AFTER 05/09/21 and the file size is over 15KB. When I run the routine the date aspects appears to work but the file cap is ignored. Could someone please help? Is it best to filter via "IF" or restrict method or a combo of both.
Thanks so much.
Option Explicit
Sub SaveOutlookAttachments()
Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olFolder As Outlook.Folder
Dim olItem As Object
Dim mi As Outlook.MailItem
Dim olAtt As Outlook.Attachment
Dim filterstring As String
Set olApp = New Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olFolder = olNS.PickFolder
For Each olItem In olFolder.Items
If olItem.Class = olMail Then
Set mi = olItem
If mi.Attachments.Count > 0 And mi.ReceivedTime > "5 / 9 / 2021" And mi.Size > 15000 Then
Debug.Print mi.SenderName, mi.ReceivedTime, mi.Attachments.Count, mi.Size
For Each olAtt In mi.Attachments
olAtt.SaveAsFile "C:\Users\John.Doe\Pictures\OUTLOOKEXPORT\Attachments Export" & Format(mi.ReceivedTime, "yyyy-mm-dd hh-nn-ss ") & olAtt.Filename
Next olAtt
End If
End If
Next olItem
End Sub
Hi Gillian, the test for size of the mail item looks fine and should work - it does for me. Bear in mind that the Size property of the mail item represents the full size of the entire email. If you want to check the size of each attachment separately, test the Size property of your olAtt variable in the second loop.
I hope it helps!
@@WiseOwlTutorials Thanks so much for getting back to me. When I run the routine based on current parameters, I still pick up 5KB PNG files which is wrong. I have tried to add "For Each olAtt In mi.Attachments.Restrict(Filterstring)" But I do not have the intellisense drop-down option in the second loop? I have added Filterstring as a variable, and although it is not included in the earlier code, I would add FilterString = "[size] > 15000 AND [receivedtime] > '05/09/2021'" just above the first "For Each" loop. Would love your help on this.
@@gillianmcnosehair9097 You can't apply the Restrict method to the object returned by the Attachments property. Just loop through the attachments as you showed in the original code you posted. Add an If statement inside this loop which tests the olAtt.Size property, not the mi.Size property.
I hope it helps!
@@WiseOwlTutorials Top, Top man. Thanks so much, Andrew. I added the following code: "For Each olAtt In mi.Attachments
If olAtt.Size > 10000 And mi.ReceivedTime > "5/09/2021" Then" and it recognised the "IF" and executed perfectly.
I've been toiling for an answer for weeks! Just stumbled upon your content and I've acquired a mass of knowledge from your excellent videos. I would like to thank you for making them available.
@@gillianmcnosehair9097 Excellent! Happy to hear that you got it working, good stuff!
Thank you!
I am having an issue when I loop through a folder (for each i in fol.items), only about half of the emails are being picked up by the macro. I've tried setting fol.items to an Outlook.Items object and sorting, but still no good. Do you have any idea what could be happening here?
Hi bobby
Awesome
Hello, I get a runtime error 76, Path not found at line "Set dir = fso.CreateFolder(dirName)". I could retrieve and save the attachments so everything was running fine until I got to the stage of creating folders for the attachments. Any idea what caused the error?
Hi Alexandre! There are a couple of possible reasons for this. One is that you haven't created all of the necessary parent folders - the CreateFolder method can only create one level at a time. Another possibility is a simple spelling error in the folder path of the value in your dirName variable.
I hope that helps!
Awesome
Thanks!