![]() |
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. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
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 |