• Subject: Re: Automating Paste In Outlook 2007
  • Author: Neil
  • Date: 30 Jul 2010
  • References: 1 2 3 4 5 6 7 8
Thanks, Ken. I'll give it a shot.

Neil

"Ken Slovak" <kenslovak@mvps.org> wrote in message
news:i2rv1i$dhu$1@news.eternal-september.org...
>I would set up a a more global Outlook.Application object and check it and
>only instantiate it if it's nothing. In the initial code when Access is
>started I'd put Set objOutlook = Nothing. Then I'd set it and check it
>whenever I needed to use it.
>
> If I started Outlook if GetObject() failed I'd use CreateObject() and set
> a Boolean to indicate that. If I started Outlook when my code was
> terminating I'd close it.
>
> So, something like this:
>
> If (objOutlook Is Nothing) Then
> ' do application init
> End If
>
>
> I would also establish a NameSpace object globally and instantiate that
> and also use the Logon code.
>
> When I got the Inspector I'd do it like this:
>
> Dim oInsp As Outlook.Inspector
> Set oInsp = .GetInspector
> oInsp.Display
> DoEvents
> oInsp.CommandBars.ExecuteMso "Paste"
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "Neil" <neil.ginsberg+newsgroup@gmail.com> wrote in message
> news:i2r8fi$c8b$1@news.eternal-september.org...
>> The code is all being run from Access (the bit of code I had the client
>> run from Outlook was just to troubleshoot from Outlook to see what kind
>> of error we were getting). This is all being run from Outlook using early
>> binding.
>>
>> Thanks for explaining about why MailItem worked from Access without a
>> reference to the Outlook object.
>>
>> Now for the $64,000 question:
>>
>> why is it, when I do:
>>
>> Dim objOutlookMsg As MailItem
>> Set objOutlookMsg = CreateItem(olMailItem)
>> With objOutlookMsg
>> .To = "as@kfksl.com"
>> .Subject = "sdljs lksj flkj"
>> .Display
>> .GetInspector.CommandBars.ExecuteMso ("Paste")
>> End With
>>
>> the code works fine, time after time; but when I do:
>>
>> Dim objOutlook As Outlook.Application
>> Dim objOutlookMsg As Outlook.MailItem
>> Set objOutlook = GetObject(, "Outlook.Application")
>> Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
>> With objOutlookMsg
>> .To = "as@kfksl.com"
>> .Subject = "sdljs lksj flkj"
>> .Display
>> .GetInspector.CommandBars.ExecuteMso ("Paste")
>> End With
>>
>> it works fine the first time it's run, but then gives "automation error"
>> on the "Paste" line the 2nd and subsequent times it's run? (And when the
>> automation error occurs, it is resolved by looping back to the "Paste"
>> line after a 1 second delay and trying again.)
>>
>> I don't know if there's an answer to that. But it's the same code --
>> except one makes an explicit reference to the Outlook object, and the
>> other doesn't. Very bizarre.
>>
>> Thanks!
>>
>> Neil
>
23 Jul 2010Automating Paste In Outlook 2007.Neil
23 Jul 2010\ Re: Automating Paste In Outlook 2007.Ken Slovak
24 Jul 2010   |- Re: Automating Paste In Outlook 2007.Neil
24 Jul 2010   \ Re: Automating Paste In Outlook 2007.Neil
26 Jul 2010      \ Re: Automating Paste In Outlook 2007.Ken Slovak
27 Jul 2010         |- Re: Automating Paste In Outlook 2007.Neil
28 Jul 2010         |  \ Re: Automating Paste In Outlook 2007.Ken Slovak
29 Jul 2010         |     \ Re: Automating Paste In Outlook 2007.Neil
29 Jul 2010         |        \ Re: Automating Paste In Outlook 2007.Ken Slovak
30 Jul 2010         |           \ Re: Automating Paste In Outlook 2007.Neil
27 Jul 2010         \ Re: Automating Paste In Outlook 2007.Neil
Contact Us
All times are in (US) Eastern Daylight Time (GMT -4:00)