Pulling Text to an Email. Help!

G

Guest

Hello

I have one heck of a head scratcher here for myself. I have been writing
new macros for my job as we upgrade from Outlook 2003 to Outlook 2007. The
Macros I am writing are executed from a reply email, it then accesses a word
document and copies it's contents, closes word, and paste's it to the reply
email. The problem I am running in to is with the ActiveWindow command. It
get's as far as the "selection.paste" and hits a runtime 91 error. Here is
what I have.

Sub Test()
'
' We need an easy pointer back to our new e-mail message, such as:
Set TargetDoc = ActiveWindow


' Now we open the canned response
Dim objWord As word.Application
Set objWord = New word.Application
objWord.Visible = True
objWord.Documents.Open "c:\a.docx", , , True


' Select and Copy and Close Word
Selection.WholeStory
Selection.Copy
Selection.End = True
objWord.Quit



' Now we return focus to our e-mail message and paste the text
TargetDoc.Activate
Selection.Paste


' Clean up
Set objDoc = Nothing
Set objSel = Nothing


End Sub

If I remove the objWord.Quit, it just posts the text directly in to the same
document, which tells me that Outlook does not understand that the Window I
executed it from is where it needs to be paste in to.

Any suggestions on how I fix this? I have run out of ideas.
 

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