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 -

--
Bill Billmire

Re: VBScript: Printing question... by Jonathan

Jonathan
Thu Jan 06 15:53:17 CST 2005

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" <BillBillmire@discussions.microsoft.com> wrote in message
news:A3F3D2E2-7187-41A9-B24F-F030A28DAA11@microsoft.com...
>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 -
>
> --
> Bill Billmire


Re: VBScript: Printing question... by BillBillmire

BillBillmire
Thu Jan 06 16:11:11 CST 2005

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" wrote:

> 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" <BillBillmire@discussions.microsoft.com> wrote in message
> news:A3F3D2E2-7187-41A9-B24F-F030A28DAA11@microsoft.com...
> >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 -
> >
> > --
> > Bill Billmire
>
>