Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Appending Text to Subject Field in Outlook 1

Status
Not open for further replies.

drace1111

Technical User
Mar 24, 2003
47
US
I need to create a VBA macro that will append a text string to the end of the subject line in Outlook. This will probably be firerd off by a button. Since I'm not a VBA programmer, I'm not even sure where to start. Any help is appreciated.
 
Can you be more specific here? What application are you calling this from? What button? What email item??

Regards,
Zack Barresse

Simplicity is the ultimate sophistication. What is a MS MVP? PODA
- Leonardo da Vinci
 
I'm calling from within Outlook, and I'll be creating a button on the standard toolbar in the new mail message window that, when clicked, will append a set string of text to the end of the subject field.
 
the ActiveInspector object is what you need.

Code:
Sub AddToEndOfSubjectLine()
If ActiveInspector Is Nothing Then Exit Sub
ActiveInspector.CurrentItem.Subject = ActiveInspector.CurrentItem.Subject + " HELLO!"
End Sub

mr s. <;)

 
Thanks, this is a step in the right direction, but it's replacing any existing text in the subject field. I need it to append to the end.

Getting close!
 
should have been "&" and not "+", sorry, too used to c#.

"a = a & b" should append string b to string a, if it doesn't then you've typed it wrongly.


mr s. <;)

 
if it doesn't then you've typed it wrongly
or a was empy ...
 
I replaced the "+" with a "&", but any existing text is still being replaced with the string, in this case HELLO!. Anything else that might be causing this?
 
This is what I have:

Code:
Sub AddToEndOfSubjectLine()
If ActiveInspector Is Nothing Then Exit Sub
ActiveInspector.CurrentItem.Subject = ActiveInspector.CurrentItem.Subject & " HELLO!"
End Sub
 
i think the problem is that you've a new item, and the subject on the item is blank, although it is non-blank in the inspector.

Code:
Sub AddToEndOfSubjectLine()
If ActiveInspector Is Nothing Then Exit Sub
ActiveInspector.CurrentItem.Save
ActiveInspector.CurrentItem.Subject = ActiveInspector.CurrentItem.Subject & " HELLO!"
End Sub


mr s. <;)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top