Automation Between Outlook 2003 and Word 2000

B

blgsai

We used to have Outlook 2000 with Word 2000 and I used the automation code
below which worked fine. We then migrated to Outlook 2003 with Word 2000 and
the same piece of code does not work. What am I missing? Pls help. See code
below:

Dim myOutlook As Object
Dim myInspector As Object

On Error Resume Next

Set myOutlook = GetObject(, "Outlook.Application")

If myOutlook Is Nothing Then
Set myOutlook = CreateObject("Outlook.Application")
End If

On Error GoTo 0

If myOutlook Is Nothing Then
MsgBox "Application Not Available"
End If

Set myInspector = myOutlook.ActiveInspector
myInspector.Activate
MsgBox myInspector.CurrentItem.Subject, vbInformation

Set myOutlook = Nothing
 
D

Doug Robbins

Do you have a reference set to the correct Outlook Object Library -
Microsoft Outlook 11.0 Object Library - in the case of Outlook 2003.

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
B

blgsai

Yes I do have a reference to the object library.

Doug Robbins said:
Do you have a reference set to the correct Outlook Object Library -
Microsoft Outlook 11.0 Object Library - in the case of Outlook 2003.

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
J

Jean-Guy Marcil

blgsai was telling us:
blgsai nous racontait que :
We used to have Outlook 2000 with Word 2000 and I used the automation
code below which worked fine. We then migrated to Outlook 2003 with
Word 2000 and the same piece of code does not work. What am I
missing? Pls help. See code below:

"does not work" is kind of vague.
What exaclty happens? When you debug, which line throws the error? Do you
get an error message? If so, what is it?
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
D

Doug Robbins

And what line of code is highlighted when the error occurs

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
B

blgsai

It fails at Line 1 and if I comment out Lines 1, 2 and 4 and leave just line
3, it still fails at line 3.
1: Set myOutlook = GetObject(, "Outlook.Application")

2: If myOutlook Is Nothing Then
3: Set myOutlook = CreateObject("Outlook.Application")
4: End If

I made sure to check that the project has the references and I have the
following references:
- Visual Basic for Applications
- Microsoft Word 9.0 Object Library
- OLE Automation
- Microsoft Office 9.0 Object Library
- Microsoft Outlook 11.0 Object Library
- Microsoft Forms 2.0 Object Library

Thx.
 
J

Jean-Guy Marcil

blgsai was telling us:
blgsai nous racontait que :
It fails at Line 1 and if I comment out Lines 1, 2 and 4 and leave
just line 3, it still fails at line 3.
1: Set myOutlook = GetObject(, "Outlook.Application")

2: If myOutlook Is Nothing Then
3: Set myOutlook = CreateObject("Outlook.Application")
4: End If

I made sure to check that the project has the references and I have
the following references:
- Visual Basic for Applications
- Microsoft Word 9.0 Object Library
- OLE Automation
- Microsoft Office 9.0 Object Library
- Microsoft Outlook 11.0 Object Library
- Microsoft Forms 2.0 Object Library
Have you tried changing

Dim myOutlook As Object
Dim myInspector As Object

to

Dim myOutlook As Outlook.Application
Dim myInspector As Outlook.Inspector

I think it is better to use explicit assignments whenever you can.
Maybe your code was working under Word/Outlook 2000 because the compiler
correctly guessed what kind of object myOutlook was.
Now that you are using an Outlook version that is different from the Word
one, maybe the compiler cannot guess anymore.

It may be an Ealry vs Late binding issue.
Normally, we use
Dim myOutlook As Object
in late binding, but you use early binding...

See
http://word.mvps.org/faqs/interdev/EarlyvsLateBinding.htm
for more on the pros/cons of Early/Late binding.

If not, have you tried posting in an Outlook group?

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
B

blgsai

Thank You - that worked. I know I tried it but I must have missed something
because it now works using early binding. I really appreciate it. Thx.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top