سؤال

I'm trying to create a macro that will add some text into the subject of a message and then send the message. I ahve created a button on the ribbon that the user will click to add (Secure) into the subject line and send the message.

I'm using the following which I've put together from several sources I found online.

Sub InsertSubject()

Dim objMsg As Outlook.MailItem

'Get the currently open message'

Set objMsg = Outlook.Application.ActiveInspector.CurrentItem

objMsg.Subject = CurrentItem.Subject & "(Secure) "

'Destroy the object to avoid memory leaks'
objMsg.Send
Set objMsg = Nothing


End Sub

when I run this I get a Run-time error 424 Object Required. It appears to have an issue with the following line

objMsg.Subject = CurrentItem.Subject & "(Secure) "

If I remove the CurrentItem.Subject, the code works but obviously just replaces what ever subject with (Secure).

Any help would be greatly appreciated.

هل كانت مفيدة؟

المحلول

I think you are intending to do objMsg.Subject = objMsg.Subject & "(Secure) ".

Note that you are trying to use CurrentItem which is not necessarily the same as Outlook.Application.ActiveInspector.CurrentItem. I'm not that familiar with Outlook object model but I bet CurrentItem when called on it's own is not valid.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top