VBA correction required to Extract Emails outlook to excel

faraz502

Board Regular
Joined
Mar 26, 2014
Messages
127
Office Version
  1. 2016
Platform
  1. Windows
Sir help needs in this VBA, Currently, VBA export only inbox items to excel, can I extract all incoming outlook subfolder emails to excel only junk items will exclude.

Current Coding.

Option Explicit
Const xlUp As Long = -4162 'Set the enumeration for Excel's xlup
Private WithEvents inboxItems As Outlook.Items
Private Sub Application_Startup()
Dim outlookApp As Outlook.Application
Dim objectNS As Outlook.NameSpace
Set outlookApp = Outlook.Application
Set objectNS = outlookApp.GetNamespace("MAPI")
Set inboxItems = objectNS.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub inboxItems_ItemAdd(ByVal Item As Object)

Dim Msg As Outlook.MailItem
Dim ExApp As Object
Dim ExWb As Object
Dim DirSenderName As String '<- added
Dim Attach As Attachment
Dim AttachFolder As String
Dim FileName As String
Dim EmailRow As Long
Dim AttachRow As Long
Dim AttachNum As Long
Dim FileNumb As Long
Dim ErrNumb As Long
Dim WkBkOpen As Boolean


If TypeName(Item) = "MailItem" Then
FileName = "c:\Working\Daily E-mail\works\Outlook_Email_Manager.xlsm"
If FileName = "" Then
MsgBox "Please add a full file name for your Excel application"
Exit Sub
End If
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,223,247
Messages
6,171,004
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top