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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook macro, text in subject field

Status
Not open for further replies.

ron513

Technical User
Mar 9, 2004
31
US

I need assistance creating a macro for outlook to add a specific string of text to the subject field of a message. The user would open a new message run the macro and the text would be entered in the subject field as well as the ability to run the macro on a forward or reply message.

Thanks,

Ron
 
A message is a MailItem. One of its properties is Subject, which is a string property. It can take whatever text you want, either as a given string;
Code:
Dim mItem As MailItem
    With mItem
        .To = "Anybody@home.com" 
        .Subject = "some text" 
        .Body = "yadda yadda yadda" 
        .Display 
    End With

or a string variable.
Code:
Dim strSomeText As String
strSomeText = "zippty do-dah"
    With mItem
        .To = "Anybody@home.com" 
        .Subject = strSomeText
        .Body = "yadda yadda yadda" 
        .Display 
    End With

If your code is in an accessible module, then it makes no difference if it is a new message, a reply, or a forward. All messages are MailItems, and all use strings for Subject.


Gerry
My paintings and sculpture
 
Gerry,

Thanks for the reply. It appears I need a little hand holding on this.
I’m receiving the error message “object variable or with block variable not set”
What am I doing wrong?

What is an “accessible module” and if the user selected Word as the e-mail editor should the macro be in Normal.dot global template?

BTW your art is very impressive, particularly the stone carvings.

Thanks,

Ron
 
I’m receiving the error message “object variable or with block variable not set”
What am I doing wrong?

Do you have a reference set to "Microsoft Outlook ##.# Object Library"? The # sign, of course, being whatever is the greatest number available in your references... if you are using Office 2003, then it's 11.0.

To see your references, go to:

Tools -> References

Or if that one doesn't get it done, then try the "OLE Automation" reference - that might be the one you need, I forget.

If that doesn't fix the problem, post here exactly which line of code that is giving the error message.

--

"If to err is human, then I must be some kind of human!" -Me
 
And actually, this should be a post in the VBA forum.

kjv is correct. Most likely you do not have a reference. However, we don't know the full code you are using. I did not include the code for the creation of the Outlook instance, or the MAPI object, etc. etc. So I don't know exactly what you have done to cover that.

Where are you running this from? Outlook (which is what I thought you were doing) or Word?

Post a thread in the VBA forum, with code. I am sure it will be handled there.


Gerry
My paintings and sculpture
 
I am running this from outlook and do have the suggested references. Shifting priorities has moved this down my list so I have not worked on it since the first try. Subsequent posts will be in the VBA forum.
Thanks again.

Ron
 
ron513, for informational purposes, please post the link to the new thread in this thread, in case anyone tries to follow your progress.

Thanks.

--

"If to err is human, then I must be some kind of human!" -Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top