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