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.
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.