Link to home
Start Free TrialLog in
Avatar of timnorvel
timnorvel

asked on

VBA -Launch Word from Outlook - beginners question

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
ASKER CERTIFIED SOLUTION
Avatar of Soluch
Soluch

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
Avatar of timnorvel
timnorvel

ASKER

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.
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.