Page 1 of 3 123 LastLast
Results 1 to 10 of 29

Outlook VBA help

This is a discussion on Outlook VBA help within the General Excel Discussion & Other Questions forums, part of the Question Forums category; Could someone help me create a code in Outlook that would parse certain information from my email and then input ...

  1. #1
    Board Regular
    Join Date
    Sep 2011
    Posts
    84

    Default Outlook VBA help

    Could someone help me create a code in Outlook that would parse certain information from my email and then input it into an exsisting excel spreadsheet?

  2. #2
    Board Regular Trevor G's Avatar
    Join Date
    Jul 2008
    Location
    Tamworth, Staffordshire
    Posts
    5,456

    Default Re: Outlook VBA help

    This code will run from Excel then list all the emails in your inbox.
    ListAllItemsInInbox()
    'You have to Add the reference to Outlook
    'Select Tools > References > Search for Microsoft Outlook XX.Object Library
    Dim OLF As Outlook.MAPIFolder, CurrUser As String
    Dim EmailItemCount As Integer, i As Integer, EmailCount As Integer
    Application.ScreenUpdating = False
    Sheets.Add ' create a new workbook
    ' add headings
    Cells(1, 1).Formula = "Subject"
    Cells(1, 2).Formula = "Recieved"
    Cells(1, 3).Formula = "Attachments"
    Cells(1, 4).Formula = "Read"
    With Range("A1:D1").Font
    .Bold = True
    .Size = 14
    End With
    Application.Calculation = xlCalculationManual
    Set OLF = GetObject("", _
    "Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
    EmailItemCount = OLF.Items.Count
    i = 0: EmailCount = 0
    ' read e-mail information
    While i < EmailItemCount
    i = i + 1
    If i Mod 50 = 0 Then Application.StatusBar = "Reading e-mail messages " & _
    Format(i / EmailItemCount, "0%") & "..."
    With OLF.Items(i)
    EmailCount = EmailCount + 1
    Cells(EmailCount + 1, 1).Formula = .Subject
    Cells(EmailCount + 1, 2).Formula = Format(.ReceivedTime, "dd.mm.yyyy hh:mm")
    Cells(EmailCount + 1, 3).Formula = .Attachments.Count
    Cells(EmailCount + 1, 4).Formula = Not .UnRead
    End With
    Wend
    Application.Calculation = xlCalculationAutomatic
    Set OLF = Nothing
    Columns("A:D").AutoFit
    Range("A2").Select
    ActiveWindow.FreezePanes = True
    ActiveWorkbook.Saved = True
    Application.StatusBar = False
    End Sub
    Trevor
    I am on a learning curve of life, I know a little but like to share what I have learnt with others.
    I am using Microsoft Office 2003 to 2010
    Please remember everyone here is a volunteer, so if you have had a reply to your thread be courteous and acknowledge this.

  3. #3
    Board Regular
    Join Date
    Sep 2011
    Posts
    84

    Default Re: Outlook VBA help

    And I'm assuming I can make it list certain information that's in my inbox?

  4. #4
    Board Regular Trevor G's Avatar
    Join Date
    Jul 2008
    Location
    Tamworth, Staffordshire
    Posts
    5,456

    Default Re: Outlook VBA help

    This will list all emails, if you need to do something like search for words then you could look to apply a filter after this code. What do you need to search for?

    So you would need something like this

    Range("A1").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$D$50000").AutoFilter Field:=1, Criteria1:= _
    "=*What text*", Operator:=xlAnd
    Trevor
    I am on a learning curve of life, I know a little but like to share what I have learnt with others.
    I am using Microsoft Office 2003 to 2010
    Please remember everyone here is a volunteer, so if you have had a reply to your thread be courteous and acknowledge this.

  5. #5
    Board Regular
    Join Date
    Sep 2011
    Posts
    84

    Default Re: Outlook VBA help

    How do i tweek it if I want to get information from my subfolder instead of the inbox?

  6. #6
    Board Regular Trevor G's Avatar
    Join Date
    Jul 2008
    Location
    Tamworth, Staffordshire
    Posts
    5,456

    Default Re: Outlook VBA help

    You would need something along the lines of this.

    I have just found a website that might help you

    http://www.ozgrid.com/forum/showthre...t=93067&page=1

    ' subfolders and items within Inbox

    For Each olFolder In olInbox.Folders

    i = Range("F1") + 2
    For Each olItem In olFolder.Items
    Cells(i, 1) = olItem.SenderName ' Sender
    Cells(i, 2) = olItem.Subject ' Subject
    Cells(i, 3) = olItem.ReceivedTime ' Received
    Cells(i, 4) = olItem.ReceivedByName ' Recepient
    Cells(i, 5) = olItem.UnRead ' Unread?


    i = i + 1
    Next


    Next
    Trevor
    I am on a learning curve of life, I know a little but like to share what I have learnt with others.
    I am using Microsoft Office 2003 to 2010
    Please remember everyone here is a volunteer, so if you have had a reply to your thread be courteous and acknowledge this.

  7. #7
    Board Regular
    Join Date
    Sep 2011
    Posts
    84

    Default Re: Outlook VBA help

    thanks a bunch...I'll check it out!

  8. #8
    Board Regular
    Join Date
    Dec 2005
    Location
    Basingstoke (UK)
    Posts
    1,887

    Default Re: Outlook VBA help

    If you then want to extract information from the Body of the email, you would need to save the email as a (temporary) text file and then open the text file to read the content. However, you would need to find someway of identifying what you are looking for.
    Never give way to anger - otherwise in one day you could burn up the wood that you collected in many bitter weeks.

  9. #9
    Board Regular
    Join Date
    Sep 2011
    Posts
    84

    Default Re: Outlook VBA help

    Quote Originally Posted by Trevor G View Post
    This code will run from Excel then list all the emails in your inbox.
    so why do you on this line:

    Application.Calculation = xlCalculationManual why turn this to manual?
    Application.Calculation = xlCalculationAutomatic again, what is the point of changing this within the code?

  10. #10
    Board Regular
    Join Date
    Dec 2005
    Location
    Basingstoke (UK)
    Posts
    1,887

    Default Re: Outlook VBA help

    If calculation mode is set to 'auto', all open workbooks may recalculate when you update a worksheet cell. It is safer to set to manual before doing this (where appropriate) in VBA and then set it back to whatever it was before finishing the process.
    More information at:
    http://support.microsoft.com/kb/214395
    Never give way to anger - otherwise in one day you could burn up the wood that you collected in many bitter weeks.

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

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


DMCA.com