A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

New to Outlook Programming. Need code tweak, please.



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 17th 06, 07:05 PM posted to microsoft.public.outlook.program_vba
Angyl
external usenet poster
 
Posts: 38
Default New to Outlook Programming. Need code tweak, please.

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!
  #2  
Old May 17th 06, 07:43 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default New to Outlook Programming. Need code tweak, please.

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
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Angyl" wrote in message ...
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!

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Programming OUTLOOK ARCHIVE location BMP Outlook and VBA 2 May 11th 06 05:43 PM
Programming changes to XML properties Ray Jackson Outlook and VBA 1 February 7th 06 01:06 PM
Next Step in Programming for Office C.W. Billow Outlook and VBA 1 January 23rd 06 02:24 PM
Programming code needed for appointment colin.coady Outlook - Using Forms 0 January 19th 06 03:32 AM
Programming form Colin Coady Outlook - Calandaring 3 January 19th 06 03:21 AM


All times are GMT +1. The time now is 07:18 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.