Solved

VBA -Launch Word from Outlook - beginners question

Posted on 2004-04-26
3
557 Views
Last Modified: 2012-06-27
Hi,

I am trying to teach myself how to program in Outlook from a book.  I am now playing with VBA.  The book is written for Outlook 2002, but I am using 2003.  Here is the simple code they have me write:

Public Sub LaunchWordMail()
On Error Resume Next
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Set wdApp = CreateObject("Word.Application")
Set wdDoc = _
    wdApp.Documents.Add(DocumentType:=wdNewEmailMessage)
wdApp.Visible = True
wdApp.ActiveWindow.EnvelopeVisible = True
End Sub

This is supposed to launch a new email message, using Word as the editor.  It works on my 2002 machine but when I try it on my 2003 machine I get the following error:

Can't find project or library.

It then highlights "wdNewEmailMessge".  I have verified that the Microsoft Word 11.0 Object Library is selected in my references, and when I look through the help files it looks like I should be able to use wdNewEmailMessage.

Any thoguhts?  (and remember, I have no idea what i'm doing : )

Thanks,
tim
0
Comment
Question by:timnorvel
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
Soluch earned 250 total points
ID: 10967338
Hi Tim,

Try adding "Word." to "wdNewEmailMessage", i.e:

Set wdDoc = _
    wdApp.Documents.Add(DocumentType:=Word.wdNewEmailMessage)

I've had similar problems with Microsoft Access.  It may be that you have other references missing, not necessarily the Microsoft Word 11.0 object.  Check your references again, but in any event hopefully the above line of code will fix the problem.

Soluch.

0
 

Author Comment

by:timnorvel
ID: 10981233
Yes, that fixed it!!! Thanks so much.  So, the reason it didn't work is because I am missing a reference to something?  Is there a reference I should look for?  Not that I really need it now that it works this way... just seeking to understand.
0
 
LVL 2

Expert Comment

by:Soluch
ID: 10981534
The most likely reason is that you are missing a reference.  You mention that it works on your 2002 machine but not your 2003 one, so I think the 2002 machine has some files that are referenced by the macro that are missing on the 2003 machine.

Best way to check is to go to the Visual Basic Editor screen in Outloook (Tools->Macro->Visual Basic Editor or press Alt-F11), then from there view the references (Tools->References).  Look at all the ticked ones and see if any include the word “MISSING:”, if so then those are the ones that you will need to either dereference or copy from your old machine.  If you copy them over you will need to register them as well, using Regsvr32.exe from the command prompt.  If you are unsure how to do this a good place to start is: http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q249/8/73.asp&NoWebContent=1

You could also type in "Regsv32" into google, or "Registering DLL", etc.  Of course there could be a totally different reason why it's not working... :)

Soluch.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now