Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2005

Tip: Looking for answers? Try searching our database.

VBScript: Printing question...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bill Billmire - 06 Jan 2005 21:45 GMT
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 -

Signature

Bill Billmire

Jonathan West - 06 Jan 2005 21:53 GMT
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.

Signature

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

>I have some VBScript (in an Outlook Form), that calls
> "CreateObject("Word.Application").  The script processes some data then at
[quoted text clipped - 57 lines]
>
> Bill Billmire -
Bill Billmire - 06 Jan 2005 22:11 GMT
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 -

> Hi Bill,
>
[quoted text clipped - 73 lines]
> >
> > Bill Billmire -
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.