Excel VBA Introduction Part 29.5 - Copying Emails from the Outlook Inbox

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ม.ค. 2025

ความคิดเห็น •

  • @enrikekasijas705
    @enrikekasijas705 3 ปีที่แล้ว +1

    Thank you. As always internet provides so complicated solutions to problems people made for no reason and you present impossible things in a way everyone can understand and apply.
    Best channel of all time.

  •  ปีที่แล้ว +1

    That is an incredible video, it helps me a lot!.. i was searching for this information in youtube channels from Mexico, but i could not find it anywhere. Thank you very much my friend!, greetings from Mexico.

    • @WiseOwlTutorials
      @WiseOwlTutorials  ปีที่แล้ว

      Ola! You're very welcome, I'm happy to hear that the videos have helped you. Thank you so much for the kind comments and for watching!

  • @technickuk
    @technickuk 5 ปีที่แล้ว +1

    Great video, I really like the pace and fluidity of your presentation.

  • @sashatv138
    @sashatv138 5 ปีที่แล้ว +1

    I have to say - Andrew, you are brilliant. Thank you!

  • @kherratabdesselem6119
    @kherratabdesselem6119 4 ปีที่แล้ว +2

    thank you for your videos are a treasure

  • @antrikshsharma6990
    @antrikshsharma6990 5 ปีที่แล้ว +3

    Wow, Andrew, thank you for posting a video after aeons, I started learning VBA in 2017 and since then I have considered you as my mentor. Would you be posting more videos in future? Something must be wrong with me but your videos are more entertaining than Netflix.

  • @selvan1264
    @selvan1264 2 ปีที่แล้ว +1

    Thank you for the nice video! Could I check if you have video on how to reply or forward emails using excel VBA? Thank you much for your help time

  • @rambone81
    @rambone81 3 ปีที่แล้ว +1

    This was extremely helpful. Thank you for this video!

    • @WiseOwlTutorials
      @WiseOwlTutorials  3 ปีที่แล้ว

      You're very welcome Jj! Happy to hear you found it useful and thanks for watching!

  • @kalyansaha9237
    @kalyansaha9237 5 ปีที่แล้ว +1

    Welcome back Andrew ! ✨✨✨

  • @shinrafahell
    @shinrafahell 3 ปีที่แล้ว +1

    Very useful tutorial, thank you.

    • @WiseOwlTutorials
      @WiseOwlTutorials  3 ปีที่แล้ว

      You're very welcome Rafael! Thank you for watching and for taking the time to leave a comment!

  • @thres34
    @thres34 5 ปีที่แล้ว

    Over the moon, you back again

    • @thres34
      @thres34 5 ปีที่แล้ว

      @@WiseOwlTutorials I was wandering if you have done some videos on recording macros? many thanks

    • @thres34
      @thres34 5 ปีที่แล้ว

      @@WiseOwlTutorials Hi, just in general for example recording , some tips and shortcuts to improve efficiency ,saving the Marcos to be used with multi-spreadsheet. thanks

  • @nagnihotri
    @nagnihotri 5 ปีที่แล้ว

    First of all Very big thanks for this Video.
    And please make a video on How to do same when we have more than One Email A/C configured and we want to copy emails from a particular Email id.
    Thanks

  • @zzzzzzzzzzzzzzzz9
    @zzzzzzzzzzzzzzzz9 5 ปีที่แล้ว

    You are back 😍

  • @Santhosh-vt4gk
    @Santhosh-vt4gk 4 ปีที่แล้ว

    Excellent tutorial! Can you please share code to change the default folder cos I have multiple mailboxes setup in my outlook. Thanks!

  • @jordan1048
    @jordan1048 2 ปีที่แล้ว +1

    Thanks for the info! Would it be possible to insert an embedded outlook email as an object using vba?

    • @WiseOwlTutorials
      @WiseOwlTutorials  2 ปีที่แล้ว

      Hi Jordan! Yes, check out the Add method of the OLEObjects collection learn.microsoft.com/en-us/office/vba/api/excel.oleobjects.add
      I hope it helps!

  • @zaimcfpa7242
    @zaimcfpa7242 5 ปีที่แล้ว +1

    YOU ARE WONDERFUL THANK YOU

  • @selvan1264
    @selvan1264 2 ปีที่แล้ว

    Thank you for the useful videos. Could I check how to reply and forward emails using excel vba? Do you have a video for that? Thank you

    • @WiseOwlTutorials
      @WiseOwlTutorials  2 ปีที่แล้ว +1

      Hi Selva! You can apply the Reply or Forward methods to a MailItem object. Both methods return a MailItem object which you can then manipulate in the same way as a new email. To get a reference to an email that you want to forward or reply to you can use the Find or Restrict methods. We have videos on those topics in this playlist th-cam.com/play/PLNIs-AWhQzcleylKSN4MS-tJloReq0XcK.html
      I hope it helps!

    • @selvan1264
      @selvan1264 2 ปีที่แล้ว +1

      @@WiseOwlTutorials Thank you for the reply. The videos looks useful. as I am new to excel VBA it will be awesome if you happen to have video which shows a sample of how to do the actual excel VBA code for either replying and forwarding of emails...I think other viewers would be interested to know too...thank you for your consideration. Have a nice day

    • @WiseOwlTutorials
      @WiseOwlTutorials  2 ปีที่แล้ว +1

      @@selvan1264 Thanks Selva, I'll put the topic on my list!

    • @selvan1264
      @selvan1264 2 ปีที่แล้ว

      @@WiseOwlTutorials Thank you, will be nice to see the video if there is...have a nice day

  • @hadiasghari2266
    @hadiasghari2266 5 ปีที่แล้ว

    Made my day
    Thank you

  • @yasirarslan
    @yasirarslan 4 ปีที่แล้ว

    Hi, thanks for sharing this technique. My loop stops at calendar invite in my outlook inbox and whole process stops. How to skip/ avoid calendar invite while doing loop and pushed the process to complete till last email?

  • @denniscomia2815
    @denniscomia2815 4 ปีที่แล้ว

    Hello! Great tutorial!! What if I wanted to reference it to a PST folder? Is that also possible?

  • @pradeeprawatvlogs8358
    @pradeeprawatvlogs8358 5 ปีที่แล้ว

    Again thank you so much sir g 🙏🙏🙏🇮🇳 you r awesome sir awesome....

  • @kamalakotagiri7174
    @kamalakotagiri7174 4 ปีที่แล้ว

    Can we create bookmarks in mailbody and use for hyperlink with VBA?

  • @rahulm1431
    @rahulm1431 2 ปีที่แล้ว +1

    Thank you

    • @WiseOwlTutorials
      @WiseOwlTutorials  2 ปีที่แล้ว

      You're welcome Rahul, thanks for watching!

  • @virajwani7086
    @virajwani7086 4 ปีที่แล้ว

    Hey, I had some error in getting the recipient mail from outlook. I am getting my name sometimes and my email-ID sometimes. Could you help me with this. Thanks 😊

  • @kherratabdesselem6119
    @kherratabdesselem6119 4 ปีที่แล้ว

    Hi Andrew
    I neely copied your code word for word and la deuxieme part ne fonctione pas at the seting of the word doctument with the gettinginspector
    kind regards Kherrat

  • @joshdiaz4456
    @joshdiaz4456 5 ปีที่แล้ว

    Great video. I would like to copy the e-mails to a Microsoft Access form instead of a worksheet. Also what if the inbox has sub folders?

    • @joshdiaz4456
      @joshdiaz4456 5 ปีที่แล้ว +1

      @@WiseOwlTutorials Thank you so much for the quick reply! I have reviewed the ADO videos several times and I can create ADO connections confidently. I will review the tutorial for the Outlook folders and sub-folders. The wise owl videos are truly some of the best for working with VBA especially since you have covered most of the topics in depth. I can honestly say that after watching the wise owl tutorials my VBA skills have improved tremendously and I have applied what I have learned in the business world. Your work is greatly appreciated!

  • @faiz.ahmad65
    @faiz.ahmad65 3 ปีที่แล้ว

    Can we also extract gmail email subject line and sender email ids?

    • @WiseOwlTutorials
      @WiseOwlTutorials  3 ปีที่แล้ว

      Hi there! I don't have any experience working with Gmail I'm afraid. I know that Google provide an API for working with Gmail but I don't know how you'd integrate that with VBA.

  • @alessandroserranocolavite6220
    @alessandroserranocolavite6220 2 ปีที่แล้ว

    Thank you for the video! I cant download the file in website :(

    • @WiseOwlTutorials
      @WiseOwlTutorials  2 ปีที่แล้ว +1

      Hi Alessandro, apologies, this problem should now be resolved!

    • @alessandroserranocolavite6220
      @alessandroserranocolavite6220 2 ปีที่แล้ว

      @@WiseOwlTutorials dont worry, u taught me a lot, thank you 😀

  • @robertkomarek8615
    @robertkomarek8615 5 ปีที่แล้ว

    Would it be also possible to loop through Sub-Subfolders? Yes, the sub of a sub. No typo! I use OL as kind of Project Management tool though it's hard to overlook everything meanwhile. To have it summarized in one Excel-Sheet would help a lot. Some material available how to loop through inbox and subfolders but nothing further going so I guess it's
    impossible.

    • @robertkomarek8615
      @robertkomarek8615 5 ปีที่แล้ว

      @@WiseOwlTutorials Wow! Didn' t expect that! Thank u very much Sir!

  • @kashifkhanspecial
    @kashifkhanspecial 3 ปีที่แล้ว

    Hi Andrew,
    I hope you are doing well, I have one question to you, can I move all the mails (mails that category is blank) from a folder to another folder at once like copy and paste not through loop, move bulk mails at once, is this possible? if yes? please help me.
    Like if we do manually then will go to that folder then apply filter the mails then select those filtered mails and drage those mails to another folder, at once we moved all the mails to difference folder.
    Please take good care of yourself and your family.
    Thanks
    Kashif

    • @WiseOwlTutorials
      @WiseOwlTutorials  3 ปีที่แล้ว

      Hi Kashif!
      I don't know of a way to do what you're asking. The Restrict method returns a collection of filtered Items. But the Items object doesn't have a move method so you'd still need to loop through the returned items collection and apply the move method to each email separately.
      I'd be interested to hear if you discover a way to move multiple items at once!

    • @kashifkhanspecial
      @kashifkhanspecial 3 ปีที่แล้ว +1

      Andrew! thanks for the reply, sure, I am still searching the answer and I will let you know if I find any answers.
      Thanks
      Kashif

  • @arjunportail3999
    @arjunportail3999 5 ปีที่แล้ว

    Great Sir.

  • @dan_draft
    @dan_draft 3 ปีที่แล้ว

    Hi Andrew, I have a list of email address and each of them has their own assistants in their outlook contact details. How can I get the name of that assistant then copy it into a worksheet? I am having trouble referencing with Namespace.
    Thanks.

    • @WiseOwlTutorials
      @WiseOwlTutorials  3 ปีที่แล้ว

      Hi Dan! I'm not familiar with assistants in Outlook (I guess I'm not important enough to have one!). Where do you have this list of email addresses stored and where are you seeing the assistant names in the contact details? All I've got is the Microsoft Docs reference to the AssistantName property
      docs.microsoft.com/en-us/office/vba/api/outlook.exchangeuser.assistantname
      And the Docs reference to the ExchangeUser object (which AssistantName is a property of) docs.microsoft.com/en-us/office/vba/api/outlook.exchangeuser

  • @maheshchandrajoshi5991
    @maheshchandrajoshi5991 2 ปีที่แล้ว +1

    Thank u...

  • @TheRenzer9
    @TheRenzer9 3 ปีที่แล้ว

    How to print the data in cells after the first row rather than the first row itself ?

    • @WiseOwlTutorials
      @WiseOwlTutorials  3 ปีที่แล้ว

      Hi Allen, you can set the value of the n variable to 1 before beginning the For Each loop. I hope that helps!

  • @krn14242
    @krn14242 5 ปีที่แล้ว

    Thanks with ears still attached.

  • @rodrigoordenes4858
    @rodrigoordenes4858 3 ปีที่แล้ว

    Hi, the for each can be traversed in reverse ???
    thanks.

    • @WiseOwlTutorials
      @WiseOwlTutorials  3 ปีที่แล้ว

      Hi Rodrigo! You can use a variable to capture a reference to the Items of a folder, then apply the Sort method to the variable and then use the variable in the For Each loop like so:
      Dim InboxItems As Outlook.Items

      Set InboxItems = fol.Items

      InboxItems.Sort "[ReceivedTime]", True

      For Each i In InboxItems
      I hope that helps!

    • @rodrigoordenes4858
      @rodrigoordenes4858 3 ปีที่แล้ว +1

      @@WiseOwlTutorials Thank you. Yes it worked for me.

    • @WiseOwlTutorials
      @WiseOwlTutorials  3 ปีที่แล้ว

      @@rodrigoordenes4858 Excellent Rodrigo, thank you for letting us know!

  • @ErnestoEscobedo-jz4mz
    @ErnestoEscobedo-jz4mz 9 หลายเดือนก่อน +1

    thks, a lot. Regards...

    • @WiseOwlTutorials
      @WiseOwlTutorials  8 หลายเดือนก่อน

      You're very welcome, thank you for watching!

  • @kashifkhanspecial
    @kashifkhanspecial 2 ปีที่แล้ว

    Hi Andrew, I hope you are doing good and staying safe, I have one question in outlook, in a folder there are multiple mails and in this folder have many mails that have the subject "TestMail_1" and my requirement is that if the mail's subject is "TestMail_1" then I want to move this mail to another folder, and for this I am applying loop in this folder, this loop is not moving all the mails that have the subject "TestMail_1" it is only moving some of the mails not all, I don't know why but it is skipping some mails.
    For Testing purpose suppose in the source folder have 9 mails with following subject.
    1st mail Subject: TestMail_1
    2nd mail Subject: TestMail_5
    3rd mail Subject: TestMail_1
    4th mail Subject: TestMail_4
    5th mail Subject: TestMail_2
    6th mail Subject: TestMail_1
    7th mail Subject: TestMail_1
    8th mail Subject: TestMail_1
    9th mail Subject: TestMail_1
    Code:
    Set outFolderSource=namespace.Folders("emailaddress").folders("SourceFolder")
    Set outFolderDestination=namespace.Folders("emailaddress").folders("DestinationFolder")
    For each outMail in outFolderSource.Items
    If outMail.Class=olMail Then
    If Instr(outMail.Subject, "TestMail_1")>0 then
    outMail.Move outFolderDestination
    End if
    End if
    Next outMail
    My kind request to you that please help me to resolve this issue.
    Thanks
    Kashif

    • @WiseOwlTutorials
      @WiseOwlTutorials  2 ปีที่แล้ว +1

      Hi Kashif, the code looks good! I'm sorry I don't know why it would skip items. Does it skip items if you simply try to Debug.Print the email subject rather than move the email? Does it behave differently when you step through the procedure with F8 rather than running it with F5?

    • @kashifkhanspecial
      @kashifkhanspecial 2 ปีที่แล้ว +1

      @@WiseOwlTutorials Hi thanks for the reply, yes sometimes it also skips the mail when I debug the MessegaClass property, so I think it will also do the same with Subject.
      Thanks
      Kashif

  • @enrikekasijas705
    @enrikekasijas705 3 ปีที่แล้ว

    Is there some way to copy only part of the body from email ? Some emails may cause out of memory error ;D I amsking because I need to check for a specific combinations of text in subject and then if it fails in body text. If email has a lot of words it may cause crashes ;P

    • @WiseOwlTutorials
      @WiseOwlTutorials  3 ปีที่แล้ว +1

      Hi Enrike! You could use the GetInspector property of the MailItem and use that to get a reference to a Word document. You can then use Word VBA techniques to find and return any text you like from the email. Here's some basic information on the GetInspector property
      docs.microsoft.com/en-us/office/vba/api/outlook.mailitem.getinspector
      Of course you'll need to adapt it to refer to your existing emails and then work out how to find text using Word VBA docs.microsoft.com/en-us/office/vba/word/concepts/customizing-word/finding-and-replacing-text-or-formatting
      I hope that points you in the right direction!

    • @enrikekasijas705
      @enrikekasijas705 3 ปีที่แล้ว +1

      @@WiseOwlTutorials I didn't see that notification . Nice TH-cam! Thank you very much. I just got an idea regarding my macro and run into it without watching rest of your tutorials. I saw them all several times but my memory is questionable. I still need to adapt that hint from you. Just for information that someone may use. I got quite a job to do to get some lazy time at work. I am more excel functions guy than vba but Thanks to you I improved like crazy. So I use exchange account in Outlook and Excel doesn't see that account the way you pointed out but I still have access to emails. The issue will be that mail sent from other account will not be visible in the Sent Items of the exchange account. I propably will forward the mail I want and then manually move Items I sent to the archive. Although I am not there yet. Internet said that even if you send an email onbehalf than it still won't be in that exchange account mail box . That email body is troublesome because I use excel functions so I paste all data into excel cell and then convert it .Yet if mail contains several answers within and pictures than it is hard to loop through such mail and paste all data into cell. It takes a lot of time. Pictures might be the reason. Pictures do not paste into cell but coping process takes forever. I just type activecell.value = mi.body heheh Signature of each person belongs to body so it is annoying. Right now I just used instr and if there is HTTPS than the text ends but I know some mails have several answers ;P Right now the biggest issue I just solved Today was to make a sub that gets string of text made of 14 digits directly from email's subject or the body and saves it as variable. Using Excel functions it is quite simple and quite not to do. In Excel if I use function mid (activecell.value,( search (" ????????",text),lenght ) + 0 I can check if text excel found is number but than if number had zeros at the beginning they all disappear so I need to add them ;P sometimes clients type spaces between digits so I check such possibility with search "?? ???? ??" nevertheless I somehow did that using about 20 variants of text format ?????? And another sub using counter and checking if the next counter (character)in body isnumeric and if so then add another character...at the end it saves only variable with all digit characters. I don't know how I did IT but it's Thanks to you and your videos. Still I will have to convert Excel functions into vba functions to make it work faster but I don't know how yet. Still I feel great ;D
      Making such macros is really challenging and fun. I would really like to support the channel but I don't have credit card. Please add some bank account number on your official website ;)

    • @enrikekasijas705
      @enrikekasijas705 3 ปีที่แล้ว +1

      @@WiseOwlTutorials Hi. You always point my brain in the right direction ;) I am going to make that macro within 30 days ;P and then no more work at work ;) to some extent ;D

    • @WiseOwlTutorials
      @WiseOwlTutorials  3 ปีที่แล้ว +1

      @@enrikekasijas705 Hi Enrike! It sounds like you're having lots of fun solving problems with VBA and I'm happy to hear that the videos have helped you! Good luck with the remaining challenges and I hope you continue to enjoy it!

    • @WiseOwlTutorials
      @WiseOwlTutorials  3 ปีที่แล้ว +1

      @@enrikekasijas705 😀 that's the dream!

  • @volondee
    @volondee 4 ปีที่แล้ว

    thanks

  • @kashifkhanspecial
    @kashifkhanspecial 5 ปีที่แล้ว

    Hi Andrew,
    Thank you thank you thank you million times thank you so much for this lovely tutorial, God bless you.
    I have couple of problems that I am describing below.
    Problem 1:-
    Below is the code for attachments, we talked in previous comment, it is also counting those mails that does not have any attachments but have embedded images in the mail body.
    Code:-
    Sub Practice_Outlook()
    Dim objOutlook As Outlook.Application
    Dim objNamespace As Outlook.Namespace
    Dim objFolder As Outlook.Folder
    Dim objItems As Outlook.Items
    Dim objItem As Outlook.MailItem
    Dim intCount As Integer
    Dim intLoop As Integer
    Dim intAttachmentMailCount As Integer

    Set objOutlook = New Outlook.Application
    Set objNamespace = objOutlook.GetNamespace("MAPI")

    Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)
    Set objItems = objFolder.Items

    intCount = objItems.count
    intAttachmentMailCount = 0

    For intLoop = 1 To intCount

    'Check if the refrencing mail is not a mail then set the reference
    'If objItems(intLoop).Class olMeetingRequest Then
    'For checking if the referencing mail is a mail then set the reference
    'if objitems(intloop).class=olmail then
    If objItems(intLoop).Class olMeetingRequest Then
    Set objItem = objItems(intLoop)

    If objItem.Attachments.count > 0 Then
    Debug.Print objItem.Attachments(1).DisplayName
    Debug.Print "There is an attachments in the mail." & vbCrLf & _
    "Subject: " & objItem.Subject & vbCrLf & _
    "date:- " & objItem.CreationTime

    intAttachmentMailCount = intAttachmentMailCount + 1
    End If
    End If
    Next intLoop
    Debug.Print intAttachmentMailCount
    End Sub
    Problem 2:-
    In a sheet and in a column A, I have some email addresses and in column B I want to fetch their Reporting Manager Name, the code below is working fine, however whenever it is fetching the Manage Name it displays a security message to ALLOW and DENY, and it is tiresome to click each and every time to fetch the Manager Name, say I have around 100 email address then I will have to click 100 times, please advice me how can I overcome this problem.
    Code:-
    Sub GetReportingManagerNameFromAddressBook_Outlook()
    Dim colAL As Outlook.AddressLists
    Dim oAL As Outlook.AddressList
    Dim colAE As Outlook.AddressEntries
    Dim oAE As Outlook.AddressEntry
    Dim oExUser As Outlook.ExchangeUser
    Dim ws As Worksheet
    Dim r As Range, rEach As Range
    Dim lLastRow As Long

    With Sheet4
    lLastRow = .Cells(Rows.Count, "A").End(xlUp).Row
    Set r = .Range(.Cells(2, "A"), .Cells(lLastRow, "A"))
    End With

    Set colAL = Outlook.Application.Session.AddressLists
    For Each rEach In r
    For Each oAL In colAL

    If oAL.AddressListType = olExchangeGlobalAddressList Then
    Set colAE = oAL.AddressEntries
    For Each oAE In colAE
    If oAE.AddressEntryUserType = olExchangeUserAddressEntry Then
    Set oExUser = oAE.GetExchangeUser
    If oExUser.PrimarySmtpAddress = rEach.Value Then

    rEach.Offset(0, 1).Value = oExUser.GetExchangeUserManager
    Exit For
    End If
    End If
    Next oAE
    End If
    Next oAL
    Next rEach

    MsgBox "Done"

    End Sub
    Thanks once again.
    Thanks
    Kashif

    • @ivanonanga2195
      @ivanonanga2195 5 ปีที่แล้ว

      Hi @Kashif
      Maybe I'am wrong but did you try to turn off the "DisplayAlerts" ?
      like :
      Application.DisplayAlerts = False

    • @kashifkhanspecial
      @kashifkhanspecial 5 ปีที่แล้ว

      Yes I tried however it is still not working

  • @oscarrulz6551
    @oscarrulz6551 ปีที่แล้ว +1

    dude cant you track the guy (who threatened to harm you ) by his email ID and report him to the police .....also awesome channel you put out great content ......

    • @WiseOwlTutorials
      @WiseOwlTutorials  ปีที่แล้ว

      Thanks Oscar! Happy to hear you're enjoying the videos! And thanks for your concern but I don't think the threat was a serious one!

  • @paraglide01
    @paraglide01 5 ปีที่แล้ว

    Ears are highly overrated ;-)