Link to home
Start Free TrialLog in
Avatar of hank1
hank1

asked on

get an outlook or excel com object from the other

When I use perl as the controller I obtain a com obj like this:
  my $excel;
  my $class = 'Excel.Application';

  if(!($excel = Win32::OLE->GetActiveObject($class) ||
    Win32::OLE->new($class, 'Quit'))) {

Well, I've been told that it's all going to be vb now so how
do I obtain that excel.application from within an outlook
macro or the outlook.??? from an Excel macro?

I'm just learning this.  Seems the application object is
implicit when you deal with the appliction within a macro.

Also... suggest a good book.  I've already found one on VB6.
All this will be written in what ever is available at AltF11.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
While we are at it, there is also:

    Dim xlApp As Excel.Application   ' <-- needs the Excel Object Library

    Set xlApp = GetObject(, "Excel.Application)
    If xlApp Is Nothing Then
        ' no instance of Excel is running, so:
        Set xlApp = New Excel.Application
        ' hidden instance, with user control = false, so:
        xlApp.Visible = True
     End If

Finally, a cute one:

    Dim xlWkb As Excel.Workbook

    Set xlWkb = GetObject("C:\Testing\Test.xls")

All in one, find Excel and point to the open file, or open it, or create a new Excel instance, and load the file!
That's the most useful, in many cases.

Cheers!
Markus,

Great to see you in the Excel TA!

hank1: what you are seeing here is the difference between late binding (my examples) and early binding (Markus's
examples).  Early binding can sometimes help execution go a tiny bit faster, and it also allows Intellisense to help
you out in the development environment by helpfully autocompleting properties and methods and reminding you
of arguments.  Late binding has one very big advantage: it is better able to accommodate different versions of
the application you're trying to instantiate.

Patrick