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.
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.