Using the code below I have achieved to get my email body to excel. However, they are being imported form newest to oldest I need to be able to import form oldest to newest. any help is greatly appreciated.
Thanks
Thanks
VBA Code:
Sub InboxToExcel()
Dim olApp As Outlook.Application
Dim olNS As Namespace
Dim olFolder As MAPIFolder
Dim OutlookMail As Variant
Dim I As Integer
Dim MT As Long
Dim Mnth As String
Dim xMailItem As MailItem
Dim xTable As Word.Table
Dim xDoc As Word.Document
Dim xWb As Workbook
Dim xWs As Worksheet
Dim xRow As Integer
ActiveSheet.Unprotect Password:="password"
On Error Resume Next
Set xWb = ActiveWorkbook
Set xWs = ActiveSheet
xRow = 1
Set olApp = GetOL()
Set olNS = GetNS(olApp)
On Error Resume Next
MT = InputBox("WHAT MONTH BID DO YOU WANT TO IMPORT? TYPE THE MONTH NUMBER 1-JANUARY..ETC")
Mnth = MonthName(MT)
If MT = 0 Then
Exit Sub
Else
Set OutlookApp = New Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olFolder = olNS.GetDefaultFolder(olFolderInbox).Folders("Bids").Folders(Mnth)
I = 1
For Each xMailItem In olFolder.Items
Set xDoc = xMailItem.GetInspector.WordEditor
For I = 1 To xDoc.Tables.Count
Set xTable = xDoc.Tables(I)
xTable.Range.Copy
xWs.Range("Y1").Select
xWs.Paste
Range("X1").Offset(I, 0).Value = xMailItem.ReceivedTime
Range("X1").Offset(I, 0).Columns.AutoFit
Range("X1").Offset(I, 0).VerticalAlignment = xlTop
Next
Call EmailCopy
Next
I = I + 1
Set Folder = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing
Range("X:AH").ClearContents
Call TextToNumbers
End If
End Sub