Newbie question, macro to enter message text

M

Mike Hood

Hello there,

I'm brand-new to VBA and am trying to automate the following:

I have a message open; I click on Forward and manually enter the address.
Then Tab three times to the body of the text area. Ctrl-Home to make sure
I'm at the top, then enter some text - this is always the *same* text for
each message:

Blah blah line one
<blank line>
Stuff n nonsense on second line.

Then I need to go back up to the end of line one where I ctrl-v to paste
something I've previously copied to the clipboard (could always do this
straight after typing line one, I just thought it made sense to keep all the
"insert text" stuff together).

I tried recording doing this in Word (as there doesn't seem to be a recorder
in Outlook) and pasting it in to a new macro in Outlook, thusly:

Sub MyMacroName()
Selection.TypeText Text:= _
"Typing starts here. Then we have a couple of returns..."
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText Text:="...then we end."
End Sub

I tested it out before adding the pasting bit, but it says "Run-time error
'424' Object required"

Searching for this in Google gives lots of hits, all quite advanced, so I
thought I'd try out you guys and gals. What do I need to add? - I'm sure it
must be dead simple...

Sorry, this is Outlook 2000 BTW.

Thanks.
 
G

Guest

There are several ways you could do this.

The easiest method is to just simply set the MailItem.Body property with the
text. You could append to the beginning of any existing text in the message
body by simply using:

MailItem.Body = MailItem.Body & vbCrLf & "text at the end"
or
MailItem.Body = "text at the beginning" & vbCrLf & MailItem.Body

The problem part is pasting from the Windows clipboard. This is easiest if
you use the SafeInspector object from the Outlook Redemption utility
(http://www.dimastr.com), which supports clipboard functionality.

You could also enable editing the e-mail using WordMail, and then you can
use the Word object model to paste the text from a macro within Outlook. The
error you are getting is because you are using Word code in an Outlook macro
without setting the proper object variables to the required Word objects (for
instance, the Selection object is an intrinsic global object that's always
available in a Word macro, but has to be explicitly declared in another VBA
environment).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top