New to Outlook Programming. Need code tweak, please.

G

Guest

Over the last month I've gotten a crash course in VBA programming in word
that allowed me to create all sorts of neat things.

Now It's Outlook's turn.

I've created a custom form in Outlook that asks for basic contact
information. What I'd like the user to be able to do is press a button and
have it automatically open a Word Document based on a template and fill in
the fields in the document based on what is in the Outlook form.

I put together this code and tried it in Word and it works:

Private Sub NewFormButton_Click()
Documents.Add Template:= _
"C:\Documents and Settings\tallen\Application
Data\Microsoft\Templates\Test.dot" _
, NewTemplate:=False, DocumentType:=0
With ActiveDocument
.FormFields("Company").Result = ClientName
.FormFields("Phone1").Result = ClientPhone
End With

End Sub

Problem is it doesn't work in Outlook. Either I"m not attaching it to the
button right or something about the code is wrong for Outlook, cuz when you
press the button...

nothing happens.

I'm not sure if I've put the code in the right place in the Visual Basic
editor for Outlook (It's under ThisOutlookSession), or if it's the code
itself. Help!
 
S

Sue Mosher [MVP-Outlook]

Outlook has no Documents collection or ActiveDocument object. You have to instantiate a Word.Application object (CreateObject("Word.Application") to be able to use Word objects. See http://www.outlookcode.com/d/customprint.htm

You can always test whether a code procedure is running by putting a MsgBox statement in it.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

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