It would be helpful if you would step through the code and pinpoint the issue more exactly. Also, I would suggest a bit more precision in setting where to paste the copied content: oItem.Display Set objDoc = oItem.GetInspector.WordEditor Set objSel = objDoc.Windows(1).Selection objSel.Paste
Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54
"Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message news:O9L$U1QpIHA.4884@TK2MSFTNGP06.phx.gbl...
> It just crashes without any vba error message - just the Word has > encountered an error and needs to close message, followed by the fault > reporting screen. Word then restarts. > > The error occurs after the prompt for the Subject so presumably the fault > lies at > > Selection.Copy > objDoc.Range.Paste > .Display > > On the few occasions when it doesn't crash, the selected formatted text is > not pasted into the message window. > > When Outlook is already running in the background, the macro works as > intended in both Word 2003 and 2007 (both with Outlook 2007). > > -- > <>>< ><<> ><<> <>>< ><<> <>>< <>><<> > Graham Mayor - Word MVP > > My web site www.gmayor.com > Word MVP web site http://word.mvps.org > <>>< ><<> ><<> <>>< ><<> <>>< <>><<> > > > Sue Mosher [MVP-Outlook] wrote:
>> Which statement causes the crash? Error messages? >> >> >> "Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message >> news:uB3L0eIpIHA.3960@TK2MSFTNGP02.phx.gbl...
>>> Sue >>> >>> The suggestion set the little cogs in motion ;) >>> >>> The following now does work to paste the formatted text into the >>> body of the message, and I have added a routine to grab the >>> addressee information from Outlook. However while it does work when >>> Outlook is running already, it usually crashes Word when Outlook is >>> supposed to be started from the macro. >>> >>> Sub Send_Extract_As_EMail() >>> ' send the document in an Outlook Email message >>> ' 2007 Graham Mayor, Tony Jollans, Doug Robbins >>> ' & Sue Mosher >>> >>> Dim bStarted As Boolean >>> Dim oOutlookApp As Outlook.Application >>> Dim oItem As Outlook.MailItem >>> Dim objDoc As Word.Document >>> Dim strEMail As String >>> >>> strEMail = "<PR_EMAIL_ADDRESS>" >>> 'Let the user choose the contact from Outlook >>> 'And assign the email address to a variable >>> >>> strEMail = Application.GetAddress("", strEMail, _ >>> False, 1, , , True, True) >>> If strEMail = "" Then >>> MsgBox "User cancelled or no address listed", , "Cancel" >>> End If >>> >>> On Error Resume Next >>> >>> 'Get Outlook if it's running >>> Set oOutlookApp = GetObject(, "Outlook.Application") >>> >>> 'Outlook wasn't running, start it from code >>> If Err <> 0 Then >>> Set oOutlookApp = CreateObject("Outlook.Application") >>> bStarted = True >>> End If >>> >>> 'Create a new mailitem >>> Set oItem = oOutlookApp.CreateItem(olMailItem) >>> Set objDoc = oItem.GetInspector.WordEditor >>> With oItem >>> .to = strEMail >>> .Subject = InputBox("Subject?") >>> Selection.Copy >>> objDoc.Range.Paste >>> .Display >>> End With >>> >>> 'Clean up >>> Set oItem = Nothing >>> Set oOutlookApp = Nothing >>> End Sub
>>> >>> Sue Mosher [MVP-Outlook] wrote:
>>>> Yes, it should have been Set not Dim. Sorry for the confusion. >>>> >>>> >>>> "Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message >>>> news:O3DN6CEpIHA.4904@TK2MSFTNGP03.phx.gbl...
>>>>> Thanks for that. I assume the second 'Dim' was a typo? >>>>> >>>>> >>>>> Sue Mosher [MVP-Outlook] wrote:
>>>>>> You might find the recent discussion at >>>>>> http://www.outlookcode.com/threads.aspx?forumid=4&messageid=26382 >>>>>> useful, as it was on a similar subject. >>>>>>
>>>>>>> I don't know if it is a clue, but if I enter >>>>>>> .GetInspector >>>>>>> and then a period vba prompts with the options - including >>>>>>> .WordEditor >>>>>>> If I add a period to the end of that, there isn't the usual >>>>>>> prompt offering .Range etc (though it doesn't baulk at its >>>>>>> addition).
>>>>>> >>>>>> Declare a Word.Document object and instantiate it: >>>>>> >>>>>> Dim objDoc as Word.Document >>>>>> Dim objDoc = MyMessage.GetInspector.WordEditor >>>>>> >>>>>> You'll then get intellisense for objDoc. >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> "Graham Mayor" <gmayor@REMOVETHISmvps.org> wrote in message >>>>>> news:OMOY0M4oIHA.2068@TK2MSFTNGP05.phx.gbl...
>>>>>>> The only thing I do in Outlook is extract a line of code from a >>>>>>> daily e-mail and paste it into a Word table, using a variation of >>>>>>> the code we discussed on an earlier occasion. >>>>>>> >>>>>>> I don't appear to be able to do anything in code with the object. >>>>>>> >>>>>>> I don't get an OMG (?) prompt or any other prompt or error >>>>>>> message. The Outlook message window opens the addressee and >>>>>>> subject are filled and (if nothing is entered in the ".Body =" >>>>>>> line) the default theme is used. The cursor is in the body area >>>>>>> and nothing is pasted. Pressing CTRL V or clicking the Paste >>>>>>> button pastes the formatted text. >>>>>>> >>>>>>> I don't know if it is a clue, but if I enter >>>>>>> .GetInspector >>>>>>> and then a period vba prompts with the options - including >>>>>>> .WordEditor >>>>>>> If I add a period to the end of that, there isn't the usual >>>>>>> prompt offering .Range etc (though it doesn't baulk at its >>>>>>> addition). >>>>>>> >>>>>>> It doesn't make any difference whether or not Outlook is running. >>>>>>>
20 Apr 2008Re: How to get to email from Word.Graham Mayor
20 Apr 2008\ Re: How to get to email from Word.Doug Robbins - Word MVP
20 Apr 2008   \ Re: How to get to email from Word.Graham Mayor
20 Apr 2008      |- Re: How to get to email from Word.Jen
20 Apr 2008      \ Re: How to get to email from Word.Tony Jollans
20 Apr 2008         |- Re: How to get to email from Word.Jen
20 Apr 2008         |- Re: How to get to email from Word.Graham Mayor
20 Apr 2008         |  \ Re: How to get to email from Word.Graham Mayor
20 Apr 2008         |     \ Re: How to get to email from Word.Jen
20 Apr 2008         |        |- Re: How to get to email from Word.Graham Mayor
20 Apr 2008         |        |  \ Re: How to get to email from Word.Tony Jollans
21 Apr 2008         |        |     \ Re: How to get to email from Word.Graham Mayor
21 Apr 2008         |        |        |- Re: How to get to email from Word.Tony Jollans
21 Apr 2008         |        |        |  \ Re: How to get to email from Word.Graham Mayor
21 Apr 2008         |        |        \ Re: How to get to email from Word.Sue Mosher [MVP-Outlook]
22 Apr 2008         |        |           \ Re: How to get to email from Word.Graham Mayor
22 Apr 2008         |        |              \ Re: How to get to email from Word.Sue Mosher [MVP-Outlook]
22 Apr 2008         |        |                 \ Re: How to get to email from Word.Graham Mayor
22 Apr 2008         |        |                    \ Re: How to get to email from Word.Sue Mosher [MVP-Outlook]
23 Apr 2008         |        |                       \ Re: How to get to email from Word.Graham Mayor
23 Apr 2008         |        |                          \ Re: How to get to email from Word.Sue Mosher [MVP-Outlook]
20 Apr 2008         |        \ Re: How to get to email from Word.Jen
20 Apr 2008         |           \ Re: How to get to email from Word.Tony Jollans
30 Jun 2008         \ Re: How to get to email from Word.Matt
All times are in (US) Eastern Daylight Time (GMT -4:00)