ugeb
asked on
creating a macro to "write" an email
Hi,
I wanted to create a macro in Outlook 2003, but discovered it won't record macros, so I'm a little lost as to what the usual syntax is for Outlook macros (I do a lot of VB in Excel).
How can I create a macro that will create a new email (not send it, just create and populate) and insert a Word document into the body before the signature and populate the subject line?
Even better, if I have a list of names and email addresses, have outlook create an email for each email address and use the associated names to replace keywords in the Word doc. In this case, I might just want Outlook to go ahead and send the message too.
Thanks!
I wanted to create a macro in Outlook 2003, but discovered it won't record macros, so I'm a little lost as to what the usual syntax is for Outlook macros (I do a lot of VB in Excel).
How can I create a macro that will create a new email (not send it, just create and populate) and insert a Word document into the body before the signature and populate the subject line?
Even better, if I have a list of names and email addresses, have outlook create an email for each email address and use the associated names to replace keywords in the Word doc. In this case, I might just want Outlook to go ahead and send the message too.
Thanks!
ASKER
Thank you for the response, but the point is I have no idea how to do that. Regardless of where the macro or VB originates, I have no idea what the commands are or any of that. That's the crux of my problem and the real question I have.
Can you give me anything that illustrates what you're describing?
thanks
Greetings, ugeb.
Here's an Outlook macro for creating a new message from code. It includes setting the subject line and attaching a file. What you've described in your third paragraph is a mail merge. There are instructions in both Word and Outlook's online help for doing that.
Sub NewOutlookMsg()
Dim olkMessage As Outlook.MailItem
Set olkMessage = Application.CreateItem(olM ailItem)
With olkMessage
'Change the subject line text on the next line as desired
.Subject = "My Subject"
'Change the file name and path of the file to be attached
.Attachments.Add "C:\MyFile.Doc"
.Display
End With
End Sub
Cheers!
Here's an Outlook macro for creating a new message from code. It includes setting the subject line and attaching a file. What you've described in your third paragraph is a mail merge. There are instructions in both Word and Outlook's online help for doing that.
Sub NewOutlookMsg()
Dim olkMessage As Outlook.MailItem
Set olkMessage = Application.CreateItem(olM
With olkMessage
'Change the subject line text on the next line as desired
.Subject = "My Subject"
'Change the file name and path of the file to be attached
.Attachments.Add "C:\MyFile.Doc"
.Display
End With
End Sub
Cheers!
ASKER
Thank you, this definitely gets me a step closer.
What about inserting a document into the body instead of attaching it?
Can I replace the text "XXXXX" with a name or something?
Thanks!
What about inserting a document into the body instead of attaching it?
Can I replace the text "XXXXX" with a name or something?
Thanks!
Inserting the contents of a Word document in the body is possible, but I strongly recommend using the built-in mail merge capability instead. Mail merge includes the ability to replace text with data from an Outlook contact. If you really want to script your own solution, then the key is making the replaceable text unique.
ASKER
I'm not sure if this makes a difference on what you're saying, but I'm not planning on sending out a bunch of emails all at once with the text replacement.
I get requests for information frequently and I just want to send the same information to each person who requests it when they request it, and personalize it easily.
Can you give me or point me to code that gets close to this?
Thanks!
I get requests for information frequently and I just want to send the same information to each person who requests it when they request it, and personalize it easily.
Can you give me or point me to code that gets close to this?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you run a script that uses MAPI to send a mail - it is Outlook that is invoked in the background to create and send your mail.
So I wouldn't look for this functionality from within Outlook but in a script or vb-project.
Hope this makes sense.... :-)