PDA

View Full Version : Macro does not work on other Outlook client



Erka
01-17-2024, 07:12 AM
Hi,


I've a working VBA code (see att). What is does: Selecting one or more received mail items in Outlook and the macro put a TAG in front of the subject field on every selected mail item. Then every selected item is forwarded to a specific mail adres.



Sub ForwardSelectedItems()
'
Dim forwardmail As MailItem
Dim itm As Object
Dim Xsubject As String
Dim itmSel As Selection
Dim n As Long
Set itmSel = ActiveExplorer.Selection
n = itmSel.Count
Do While n > 0
Set itm = itmSel.Item(n)
Xsubject = itm.Subject
If itm.Class = olMail Then
Set forwardmail = itm.Forward
forwardmail.Recipients.Add emailto@testdomain.com
forwardmail.Subject = "[TAG] " & Xsubject
forwardmail.Display
forwardmail.Send
End If
n = n - 1
Loop
End Sub

The code works fine on one outlook client. Same macro on other pc outlook gives an error "Compile error: Syntaxerror".

On both outlook clients the object library reference "Microsoft Outlook 16.0 Object Library" is selected.

Aussiebear
01-17-2024, 03:52 PM
Welcome to VBAX Erka. I've taken the liberty to add your code directly to the post.

jdelano
01-18-2024, 07:18 AM
First thing I would check is to make sure each PCs are running the exact same version of Outlook. Even if they are referencing the same object, the Outlook application itself may cause issues if they're far apart version wise.

anniesteuber
02-17-2024, 02:35 AM
The "Compile error: Syntax error" that you are encountering when running the VBA code on a different Outlook client may be due to a difference in the version of Microsoft Outlook or a difference in the VBA environment settings. Hello Neighbor (https://hello-neighbor.io)