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
 
I cannot reproduce that.
As long as the "Microsoft Outloook 16.0 Object Library is selected", I do not get any errors in the code, other than your call to the "removeSpecial" User Defined Function that you must have elsewhere in your code, and you close the IF THEN statement and DO loop in your code (you seemed to have cut off the code before the end, in what you have posted).

Are you sure that the other users are using the same version of Office as you?
Are the using a Desktop version or Online version?
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
We all are on the same version and use the desktop version. Have you ever seen VBA code turn red before? Not breakpoint highlighted red, but the font color turned red?
 
Upvote 0
We all are on the same version and use the desktop version. Have you ever seen VBA code turn red before? Not breakpoint highlighted red, but the font color turned red?
Yes, I see it turn red when there is invalid syntax (like when I copied the code you had in your original post that was missing the quotes around the values).

Try just typing in this and hitting Enter:
VBA Code:
Set objOwner=
and you will see it turn red.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,161
Members
453,021
Latest member
Justyna P

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