Change the subject line on multiple selected emails in Outlook 2016?

Hello,

I found this snippet that changes the subject line on ONE selected email in Outlook2016:

tell application "Microsoft Outlook"
	
	set objMessage to item 1 of (get current messages)
	set dlgReply to display dialog "Subject:" default answer (get subject of objMessage) with icon 1
	if text returned of dlgReply is not "" then
		set subject of objMessage to text returned of dlgReply
	end if
	
end tell

I want to adapt it to change MULTIPLE selected emails. The following doesn’t work! Does anyone have an idea what it would take fix it, and why?

tell application "Microsoft Outlook"
	set objMessage to item 1 of (get current messages)
	set dlgReply to display dialog "Subject:" default answer (get subject of objMessage) with icon 1
	if text returned of dlgReply is not "" then
		repeat with i from 1 to the (count of (get current messages))
			set objMessage to item i of (get current messages)
			set subject of objMessage to text returned of dlgReply
		end repeat
	end if
end tell

Thanks!
Cyan

Hi Cyan,

The second script works fine for me.

If I select several messages, in the email list pane, they all get renamed with the input from the dialog.

Where does the script fail for you? Are you selecting several emails in the list pane?

HI TekNic,

Thanks for the response! There are two problems with it. The first, is, it executes when I run the script from Script Debugger, but when I run it from the script menu or Fast Scripts, it fails with:

Error Number: -1
Unknown error.

Even when it works, it does indeed change the subject line but somehow ERASES all of the text in the email itself.

I am stymied on both counts!

Thanks,
Cyan