banduwgs has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to develop summery db of existing user mail content. It was faily success. Still I suffer with following primary problem.

I can not connect the existing instance of the Outlook application. When I use following piece of code:

if ($outlook = Win32::OLE->GetActiveObject('Outlook.Application')) { print "Try 1 : Success!\n"; } else { print "Try 1 : Failed!\n"; } if ($outlook = Win32::OLE->new('Outlook.Application')) { print "Try 2 : Success!\n"; } else { print "Try 2 : Failed!\n"; }

Output comes as:

Try 1 : Failed!
Try 2 : Success!

I am using Outlook 2000 on Windows 98 SE platform. Thanks in advance for all of you can clarify this problem for me here...

Replies are listed 'Best First'.
Re: Can not connect existing Outlook
by bm (Hermit) on Aug 05, 2003 at 14:08 UTC
    Are you sure you are running Outlook when you run that code snippet? That would explain the failed  GetActiveObject call.

    But if it is, what does Win32::OLE->LastError() tell you?

    --
    bm

      Good point, but still strange! It gives 0 means no error???
      - SB
Re: Can not connect existing Outlook
by Mr. Muskrat (Canon) on Aug 05, 2003 at 14:44 UTC
    Win98 with Outlook 2000. The following works for me provided that Outlook is indeed running.
    use Win32::OLE; if ($outlook = Win32::OLE->GetActiveObject('Outlook.Application')) { print "Try 1 : Success!\n"; } else { print "Try 1 : Failed!\n"; print Win32::OLE->LastError(),"\n"; } if ($outlook = Win32::OLE->new('Outlook.Application')) { print "Try 2 : Success!\n"; } else { print "Try 2 : Failed!\n"; print Win32::OLE->LastError(),"\n"; } __DATA__ Try 1 : Success! Try 2 : Success!
Re: Can not connect existing Outlook
by Foggy Bottoms (Monk) on Aug 05, 2003 at 14:03 UTC
    Hi there Banduwugs, I've worked quite a bit on Outlook now and I ran into the same problem as you have. What is the exact configuration of your computer
    The only time I had the problem was with Win98 and a certain version of Outlook 2000. I wrote to an "Outlook guru" but to no avail - I'm afraid you'll have to either change configuration or use the new method...
    It works fine with NT/2000 and Outlook 2000/2002...
    Good luck, David.

    Heureux qui, comme Ulysse, a fait un beau voyage
    Ou comme celui-là qui conquit la Toison,
    Et puis est retourné plein d'usage et raison,
    Vivre entre ses parents le reste de son âge!

    J. du Bellay, poète angevin

      Is there anyway to open a Outlook 2000 calendar using Perl?
        Yes! It's possible, but depends on your requirements. If you are planing to get the details about Appoinments, you can use "AppointmentItem" in the object modle.
        I didn't deal a lot with appoinments. Microsoft Visual Basic - Object browser (<Alt+F11> then F2 from your outlook) and Microsoft outlook object will help you.
        - SB
        Yes there is : use the Win32::OLE methods and have a look at the Outlook Object Model and from there you should be able to figure it out...
        You can navigate through the items part and check to see whether it's actually a calendar...
        Edited 1:38 PM 8/15/03
        To have a look at the Outlook Object Model, you can use VB's editor included in Outlook by pressing Alt+F11 and then once it's opened, you can use the library (press F2). It's got all you need and is very useful.
        You can also have a look at the MSDN...
Re: Can not connect existing Outlook
by Mr. Muskrat (Canon) on Aug 05, 2003 at 14:54 UTC

    I actually prefer something like this:

    use strict; use warnings; use Win32::OLE; my $oa; eval {$oa = Win32::OLE->GetActiveObject('Outlook.Application')}; die "Outlook not installed" if $@; unless (defined $oa) { print "Outlook is not running. Attempting to start it.\n"; $oa = Win32::OLE->new('Outlook.Application', sub {$_[0]->Quit;}) or die "Oops, cannot start Outlook"; } # do something with $oa here

      It's really funny the thing happen with this code.
      I exicuted this snipplet while open Outlook. It gave me following output

      Outlook is not running. Attempting to start it.

      and terminated existing Outlook application as expected.

      I would like to know exact versions you are using. For me, it is
      Windows: 98 SE 4.10.2222 A
      Outlook: 2000 SR-1 (9.0.0.3821)

      Do you have any suggession?

      Thanks a lot for keep on your attention - SB

        Version info:
        Windows 98 4.10.1998
        Outlook 2000 SP-3 (9.0.0.6627)
        ActiveState Perl v5.6.1 built for MSWin32-x86-multi-thread, Binary build 633
        Win32::OLE version 0.1403