Consulting

Results 1 to 2 of 2

Thread: Outlook Email to Excel and Download Attachment

  1. #1

    Outlook Email to Excel and Download Attachment

    Hi

    I would like to seek for your assistance on how to run below codes since I am encountering some error. Very new to VBA and I find it really hard to understand and solve it. I would also appreciate if you could add codes to on how to download the attachment to my pc shared drive like Drive C\John\. I'm encountering error like runtime error 404 and runtime error 1004. Please, this is the second time I've posted here and yet unsolved. Kindly help me.

    Dim olApp as Outlook.Application
    Dim olNS as Outlook.Namespace
    Dim olFldr as Outlook.MAPIFolder
    Dim OlItms as Outlook.Items
    Dim olMail as Variant
    
    
    Dim 1 as Integer
    
    
    Set olApp = New Outlook.Application
    Set olNS = olApp.GetNamespace ("MAPI")
    Set OlFldr = olNS.Pickfolder
    if olFldr = "Nothing" then Exit sub
    Set olItms = olFldr.Items
    
    
    i = 1
    
    
    if olItms.ReceivedTime >= Range("B4").value then
    
    
    Range("Email_Subject").offset(1,0).Value = OutlookMail.Subject
    Range("Email_Date").offset(1,0).Value = Outlookmail.ReceivedTime
    Range("Email_Sender").offset(1,0).Value = Outlookmail.SenderName
    Range ("Email_Body").offset(1,0).Value = Outlookmail.body
    i = 1 + 1
    else
    endif
    
    
    Range("A:D").EntireColumn.Autofit
    
    
    Set Folder = Nothing
    Set olFldr = Nothing
    Set olApp = Nothing
    
    
    End Sub
    Thanks

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Errors could be the Dim one as Integer and maybe not setting a reference to the Outlook object.

    Why not respond to your other thread and resolve that first? http://www.vbaexpress.com/forum/show...ive-C&p=395888 If you follow the advice for Option Explicit given, it will help you find some errors before a run. That thread also added a loop to iterate the folder items. It does need a tweak but should be get close. That is best discussed there. Adding the extract attachment feature is trivial.

    Always Compile a project from the Debug menu before a trial run.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •