Red VBA Error

BigtunaExcel

New Member
Joined
Apr 26, 2022
Messages
7
Office Version
  1. 365
I have a VBA script for Outlook that works fine on my machine however when I paste code into my coworkers application parts of the code turns red and the error message says "Syntax Error". I tried this on a handful of machines and repeated get the same red font errors. I don't think it is reference issue, and I don't think it is a macro security issue either, but that this point any suggestions for things to try would be greatly appreciated.


Private Sub GetPDFS(mostrecentdate As Date, Optional foldername As String, Optional subfoldername As String)

Dim Inbox As Outlook.MAPIFolder

Dim Item As Outlook.MailItem
Dim Atmt As Outlook.Attachment
Dim fileName As String

Dim i As Integer
Dim subject As String
Dim ws_test As Integer
Dim attachment_counter As Integer

Dim received As Date
Dim testDate As Date

Dim NS As Outlook.Namespace
Dim objOwner As Outlook.Recipient

Set NS = GetNamespace("MAPI")
Set objOwner = NS.CreateRecipient(Sample@sample.us.com)
objOwner.Resolve

'' See if subfolder has name.
If foldername = "" Then
Set Inbox = NS.GetSharedDefaultFolder(objOwner, olFolderInbox)
ElseIf subfoldername = "" Then
Set Inbox = NS.GetSharedDefaultFolder(objOwner, olFolderInbox).Folders(foldername)
Else
Set Inbox = NS.GetSharedDefaultFolder(objOwner, olFolderInbox).Folders(foldername).Folders(subfoldername)
End If

i = 1
received = mostrecentdate + 1

'' This is based on the idea that Inbox.Items is sorted by recieved date.
Dim ct As Integer
Dim pol As String
Dim savename As String

Do While received > mostrecentdate
Set Item = Inbox.Items(i)
received = Item.ReceivedTime
senderemail = Item.Sender

If senderemail = XXXX Or senderemail = "XXX" Or senderemail = "XX" Then
subject = Item.subject
subject = removeSpecial(subject)
Body = Item.Body
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Welcome to the Board!

Look at the file on your machine (that works).
Go to the VB Editor, and from the Tools menu, go to References and note all the libraries that are selected.
Do the same on the other machines.
Are they missing the library selections? If so, find them in the list and select them.
 
Upvote 0
I double checked the references and they are the same on all machines.
Can you tell/show me what references they are, so I can see if I get those errors when I select those same references?
 
Upvote 0
1650997065902.png
 
Upvote 0
Does that code really work on your computer, as-is?
Because it appears that you have some blatant errors in red lines of code you have:

VBA Code:
Set objOwner = NS.CreateRecipient(Sample@sample.us.com)
needs double-quotes around the value in parentheses, like this:
VBA Code:
Set objOwner = NS.CreateRecipient("Sample@sample.us.com")

Likewise, you need quotes around the first senderemail value, i.e.
VBA Code:
If senderemail = XXXX Or senderemail = "XXX" Or senderemail = "XX" Then
like this:
VBA Code:
If senderemail = "XXXX" Or senderemail = "XXX" Or senderemail = "XX" Then
 
Upvote 0
Apologies. I altered the values and forgot to include the parentheses. They way you have it shown is how it is on my machine.
 
Upvote 0
So which lines are returning the errors on the other computers?
 
Upvote 0
The two I tried to highlight in red. They appear red on the users computer.

Set objOwner = NS.CreateRecipient("Sample@sample.us.com")
If senderemail = "XXXX" Or senderemail = "XXX" Or senderemail = "XX" Then
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

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