I have few shared mailbox in outlook. I created VBA in excel to extract out the email subject. But I have to click "Get Outlook" button in excel follow by click selected Inbox one by one. Is there any way that I able to schedule auto extract every each inbox instead of clicking it manually one by one?
1 Answers
Create a macro enabled workbook unless you have a suitable one available.
From the VBA Editor, click [Tools] then [References]. Check that "Microsoft Outlook nn.n Object Library" is listed near the top and ticked. If listed but not ticked, click the box to tick it. If not listed near the top, scroll down (the list is in alphabetic order) until you find this library and tick it.
Copy the code below to ThisWorkbook. Save the workbook and close it.
Open the workbook by clicking it or via Windows Scheduler. A list of the accessible stores is displayed as a demonstration. Click [OK] to exit Excel or [Cancel] to terminate the macro so you can work on the code. Warning 1: if you click [OK] all open workbooks will be closed without saving any changes. Warning 2: If you do not have a Cancel or equivalent option so the macro closes the workbook automatically, you will never be able to amend the macro.
Note: this code is a demonstration of using the Workbook Open event to run a macro and a demonstration of accessing Outlook from Excel. However, it does nothing with Outlook except list the accessible stores. If you need a further demonstration, I will try to help.
Option Explicit
Sub Workbook_Open()
' Needs reference to "Microsoft Outlook nn.n Object Library" where
' nn.n depends on the version of Outlook being used.
Dim Answer As Long
Dim Dspl As String
Dim InxS As Long
Dim OutApp As New Outlook.Application
Dim OutNs As Outlook.Namespace
Set OutNs = OutApp.Session
' Build list of all accessible stores
With OutNs
Dspl = .Folders(1).Name
For InxS = 2 To .Folders.Count
Dspl = Dspl & vbLf & .Folders(InxS).Name
Next
End With
Answer = MsgBox(Dspl, vbOKCancel)
If Answer = vbCancel Then
Exit Sub
End If
Application.DisplayAlerts = False
Application.Quit
End Sub