VBA to Export Email not working to everyone

Luna_Maria

New Member
Joined
Apr 23, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows
I created a VBA to export emails from Shared Mailbox to excel.
The code is working fine with me but other users are encountering runtime error "The attempted operation failed. An object could not be found."
Note: All users have access to the mailbox & ticked the Outlook Object library in the tool reference.

Anyone can advise what could be the issue? Is it maybe compatibility issue?
 

Attachments

  • MicrosoftTeams-image (4).png
    MicrosoftTeams-image (4).png
    14.4 KB · Views: 12
  • MicrosoftTeams-image (3).png
    MicrosoftTeams-image (3).png
    46.4 KB · Views: 10

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Can you show us the script? What line of code is it failing on?
Below is my code, error is here:

Set olFldr = olNS.Folders("Our Shared Mailbox Email")

Note: just changed the email address for confidentiality.

Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olFldr As Outlook.MAPIFolder
Dim olItem As Object
Dim olMailItem As Outlook.MailItem
Dim ws As Worksheet
Dim iRow As Long
Dim hdr As Variant

Set ws = ThisWorkbook.Worksheets("Sheet1")

Set olApp = New Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")

Set olFldr = olNS.Folders("Our Shared Mailbox Email")
Set olFldr = olFldr.Folders("ForAllocation")

ws.Cells.Clear
iRow = 2

Application.ScreenUpdating = False
For Each olItem In olFldr.Items
If olItem.Class = olMail Then
Set olMailItem = olItem
With olMailItem
ws.Cells(iRow, "A") = .Subject
ws.Cells(iRow, "B") = .ReceivedTime
ws.Cells(iRow, "C") = .Body
ws.Cells(iRow, "D") = .Sender

iRow = iRow + 1
End With
End If
Next olItem

With ws
hdr = Array("Subject", "ReceivedTime", "Body", "Sender")
.Range("A1").Resize(, UBound(hdr)) = hdr
.Columns.AutoFit
End With
Application.ScreenUpdating = False
 
Upvote 0
I was able to resolved the issue, it is how the mailbox was added. I asked user to add it as additional account instead of doing it in more settings.
 
Upvote 0

Forum statistics

Threads
1,223,098
Messages
6,170,103
Members
452,302
Latest member
TaMere

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