Open Outlook's inbox with VBA

C

CES

All,
I'm trying to open Outlook 2007 (Vista) using VBA but unfortunately I can't seem to get it to work. I have found different variations of the following:

Dim Olook As Outlook.Application
Set Olook = CreateObject("Outlook.Application")
Olook.Application.Visible = True

but when I attempt to run the code I get a VB compile error: "user defined type not defined."

Basically what I want to do is to open Outlook and go to the inbox. If anyone can help me with this I would be grateful, Thanks in advance. - CES
 
M

Michael Bauer [MVP - Outlook]

The error occurs because Outlook is unknown to you project. Add a reference
to its library.

To make Outlook visible, add an Explorer to its Explorers collection.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Quick-Cats - The most effective way to assign Outlook categories:
http://www.shareit.com/product.html?productid=300120654&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)

Am Mon, 19 Mar 2007 19:28:06 -0400 schrieb CES:
All,
I'm trying to open Outlook 2007 (Vista) using VBA but unfortunately I
can't seem to get it to work. I have found different variations of the
following:
Dim Olook As Outlook.Application
Set Olook = CreateObject("Outlook.Application")
Olook.Application.Visible = True

but when I attempt to run the code I get a VB compile error: "user defined type not defined."

Basically what I want to do is to open Outlook and go to the inbox. If
anyone can help me with this I would be grateful, Thanks in advance. - CES
 
C

CES

Michael said:
The error occurs because Outlook is unknown to you project. Add a reference
to its library.

To make Outlook visible, add an Explorer to its Explorers collection.

Michael,
I'm sorry but I'm not sure what you mean when you y "Add a references to it's library... could you possible point me to a simple example of how to open Outlook from Any Office 2007 application. Thanks - CES
 
M

Michael Bauer [MVP - Outlook]

From any Office application, go to Tools/References and select Microsoft
Outlook... from the list.

If it's really necessary to have Outlook visible then modify your code a
little bit:

Dim Olook As Outlook.Application
Set Olook = CreateObject("Outlook.Application")
Olook.Explorers.Add


--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Quick-Cats - The most effective way to assign Outlook categories:
http://www.shareit.com/product.html?productid=300120654&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)

Am Wed, 21 Mar 2007 21:08:02 -0400 schrieb CES:
Michael,
I'm sorry but I'm not sure what you mean when you y "Add a references to
it's library... could you possible point me to a simple example of how to
open Outlook from Any Office 2007 application. Thanks - CES
 
C

CES

Michael said:
From any Office application, go to Tools/References and select Microsoft
Outlook... from the list.

If it's really necessary to have Outlook visible then modify your code a
little bit:

Dim Olook As Outlook.Application
Set Olook = CreateObject("Outlook.Application")
Olook.Explorers.Add

Michael,

I've added a reference to the Microsoft Outlook 12.0 Object Library as you suggested however I am still getting errors.


Public Sub test_Click()

Dim oL As Outlook.Application
Set oL = CreateObject("Outlook.Application")

'Either of these will throw an error
'oL.Explorers.Add ' Compile Error = "Argument not Optional"
'oL.Application.Visible = True ' Run-time error 438 = Object dosent support this property or method

End Sub

If by any chance you have a clue what else might be going wrong I would appreciate your help. - CES
 
M

Michael Bauer [MVP - Outlook]

OK, you must tell Explorer.Add a folder to display:

Dim ns as Outlook.Namespace
Dim Folder as Outlook.Mapifolder

Set ns=Olook.GetNamespace("MAPI")
Set Folder=ns.getDefaultFolder(olFolderInbox)

Olook.Explorers.Add Folder

Please test it, it might be necessary later to also delete the folder by
your code. You'll see that when Outlook doesn't close properly.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Quick-Cats - The most effective way to assign Outlook categories:
http://www.shareit.com/product.html?productid=300120654&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)
Am Thu, 22 Mar 2007 13:07:56 -0400 schrieb CES:
Michael,

I've added a reference to the Microsoft Outlook 12.0 Object Library as you
suggested however I am still getting errors.
Public Sub test_Click()

Dim oL As Outlook.Application
Set oL = CreateObject("Outlook.Application")

'Either of these will throw an error
'oL.Explorers.Add ' Compile Error = "Argument not Optional"
'oL.Application.Visible = True ' Run-time error 438 = Object
dosent support this property or method
End Sub

If by any chance you have a clue what else might be going wrong I would
appreciate your help. - CES
 
Top