VBScript: Printing question...

B

Bill Billmire

I have some VBScript (in an Outlook Form), that calls
"CreateObject("Word.Application"). The script processes some data then at
the end of the procedure prints out the result. This works fine on my local
machine, however, if another user attempts the same process it does not print
the output.

Ref: [msgbox "Printing to " & objWord.ActivePrinter] below...
I added the msgbox, and now verified that on each machine the correct
printer is configured (or displayed) in the msgbox. But, the form does not
print. What I observe is; the item shows up in the respective printer
queue(s) (but only for a very brief second) then vanishes and nothing
prints... Suggestions/comments?

Current working code (except printing on other machines...)

'----------------------Printing Routine------------------------
Dim objWord
Dim strTemplate
Dim strField
Dim strField1
Dim objDoc
Dim objMark
Dim mybklist
Dim counter

Sub cmdPrint_Click()

Item.Save
Set objWord = CreateObject("Word.Application")

' Put the name of the Word template that contains the bookmarks
strTemplate = "OSR.dot"

' Location of Word template; could be on a shared LAN
strTemplate = "\\ivory\forms\" & strTemplate

Set objDoc = objWord.Documents.Add(strTemplate)
Set mybklist = objDoc.Bookmarks

For counter = 1 to mybklist.count
Set objMark = objDoc.Bookmarks(counter)
strField = objMark.Name
If strField = "SentField" then
strField1 = CStr(Item.SentOn)
Else
strField1 = Item.UserProperties(strField)
End If
objMark.Range.InsertBefore strField1
Next
msgbox "Printing to " & objWord.ActivePrinter
objDoc.PrintOut
objWord.Quit(0)

End Sub

Thanks VERY much, in advance!

Bill Billmire -
 
J

Jonathan West

Hi Bill,

You need to change this line

objDoc.PrintOut

to this

objDoc.PrintOut 0

Without this, a background print is started while the code contines to the
next line. The next like quits Word, abandoning the print!

The 0 parameter turns off background printing and forces the code to wait
until the print job has been fully sent to the print spooler.
 
B

Bill Billmire

Awesome, thanks that did the trick...
Can you tell me where I can find that level of detail with respect to the
parameters that can/are passed to that argument (.PrintOut)?

Thanks again!

Bill Billmire -

Jonathan West said:
Hi Bill,

You need to change this line

objDoc.PrintOut

to this

objDoc.PrintOut 0

Without this, a background print is started while the code contines to the
next line. The next like quits Word, abandoning the print!

The 0 parameter turns off background printing and forces the code to wait
until the print job has been fully sent to the print spooler.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup



Bill Billmire said:
I have some VBScript (in an Outlook Form), that calls
"CreateObject("Word.Application"). The script processes some data then at
the end of the procedure prints out the result. This works fine on my
local
machine, however, if another user attempts the same process it does not
print
the output.

Ref: [msgbox "Printing to " & objWord.ActivePrinter] below...
I added the msgbox, and now verified that on each machine the correct
printer is configured (or displayed) in the msgbox. But, the form does
not
print. What I observe is; the item shows up in the respective printer
queue(s) (but only for a very brief second) then vanishes and nothing
prints... Suggestions/comments?

Current working code (except printing on other machines...)

'----------------------Printing Routine------------------------
Dim objWord
Dim strTemplate
Dim strField
Dim strField1
Dim objDoc
Dim objMark
Dim mybklist
Dim counter

Sub cmdPrint_Click()

Item.Save
Set objWord = CreateObject("Word.Application")

' Put the name of the Word template that contains the bookmarks
strTemplate = "OSR.dot"

' Location of Word template; could be on a shared LAN
strTemplate = "\\ivory\forms\" & strTemplate

Set objDoc = objWord.Documents.Add(strTemplate)
Set mybklist = objDoc.Bookmarks

For counter = 1 to mybklist.count
Set objMark = objDoc.Bookmarks(counter)
strField = objMark.Name
If strField = "SentField" then
strField1 = CStr(Item.SentOn)
Else
strField1 = Item.UserProperties(strField)
End If
objMark.Range.InsertBefore strField1
Next
msgbox "Printing to " & objWord.ActivePrinter
objDoc.PrintOut
objWord.Quit(0)

End Sub

Thanks VERY much, in advance!

Bill Billmire -
 

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