Printing in Word from Outlook custom forms

D

dht

I am trying to print in Word using the below code (which I have taken from
Sue Moshers book on Outlook programming), I'm pretty new to this so I'm
pretty much guessing.

The problem is that the code doesn' print...

What do I need to look at to get this to work.
I only use 1 fill field obviously when I get this working I can get the rest
working.

I'm using Outlook 2000

Dim m_blnWeOpenedWord
Dim m_blnWordPrintBackground
Const wdDoNotSaveChanges = 0
Const olDiscard = 1

Sub CmdPrint_Click()
Dim ObjDoc
Set ObjDoc = GetWordDoc("\\Wtbnas1\Shared Data\Intranet\Commercial
Services\Word Templates/Request for Reports.dot")
Call FillFields(ObjDoc)
objDoc.Applications.Options.PrintBackground = True
objDoc.PrintOut
objDoc.Close wdDoNotSaveChanges
Call RestoreWord
Set objDoc = Nothing
End Sub

Sub FilledFields(objDoc)
Dim colFields
Set colFields = objDoc.FormFields
colFields("Date").Result = Item.Sent
Set colFields = Nothing
End Sub

Function GetWordDoc(strTemplatePath)
Dim objWord
On Error Resume Next
m_blnWeOpenedWord = False
Set objword = GetObject(, "word.application")
If objword Is Nothing Then
Set objWord = createObject("word.application")
m_blnWeOpenedWord = True
End If
m_blnWordPrintBackground = objWord.Options.PrintBackground
If StrTemplatePath = " " Then
StrTemplatePath = "Normal.dot"
End If
Set GetWordDoc = objWord.Documents.Add(StrTemplatePath)
Set objWord = Nothing
End Function

Sub RestoreWord()
Dim objWord
On Error Resume Next
Set objWord.Options.PrintBackground = m_blnWordPrintBackground
If m_blnWeOpenedWord Then
objWord.Quit
Else
objWord.Visible = True
End If
Set objWord = Nothing
End Sub

Thanks
David
 
S

Sue Mosher [MVP-Outlook]

Are you putting this code in an Outlook form? Do you have a command button
named cmdPrint? Is the form published? Does any code run?
 
D

dht

Ok the code is in the Outlook scripting box not as a macro.
Button is in place and named cmdPrint
The form is published in my Personal Forms Folder
The code seemed to have been read as when I first opened the form it read
the code and located a typo I made.

The only thing is can I specify the location of the template over a network
as in the example below?

Thanks
David
 
S

Sue Mosher [MVP-Outlook]

A UNC name should work, but yours has one slash going the wrong way, so that
might cause a problem.

--
Sue Mosher, Outlook MVP
Author of
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