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 / July 2005

Tip: Looking for answers? Try searching our database.

Trouble Printing Word Documents from Folder using VBS

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Thereal Robeen - 12 Jul 2005 20:50 GMT
I am trying to automate the printing of documents from a specified folder on
our server.  I am trying to write a VB Script to do this and run it as a
scheduled task to check the folder every minute for any files in there, print
them, then delete them. Here's what I have so far, I have only begun testing
the Word doc portion.

..............<BEGIN CODE>.................
Set objShell = CreateObject ("Shell.Application")
Set objFolder = objShell.Namespace ("M:\IMSU\PrintFolder")

For Each strFileName in objFolder.Items
  If objFolder.GetDetailsOf (strFileName, 2) = "Microsoft Word Document" Then
    Set objWord = CreateObject("Word.Application")
    set docWord = objWord.Document.Open(strFileName)
    objWord.ActiveDocument.Printout Background:=False
    objWord.ActiveDocument.Close saveChanges:=wdDoNotSaveChanges
    objWord.Quit
  elseif objFolder.GetDetailsOf (strFileName, 2) = "Microsoft Excel
Workbook" Then
    'Future Code
  elseif objFolder.GetDetailsOf (strFileName, 2) = "Microsoft PowerPoint
Presentation" Then
    'Future Code
  else 'Print other files if not office docs
       objFolder.Item("M:\IMSU\PrintFolder\" &
strFileName).InvokeVerbEx("Print")
  end if

Next

Const DeleteReadOnly = TRUE

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile("M:\IMSU\PrintFolder\*.*"), DeleteReadOnly
...................<END CODE>...................

The Delete portion works OK, but I keep getting a Windows Script Host
'Expected Statement' Compile Error on the PrintOut line.  Any help would be
greatly appreciated.  Thank you.
Jay Freedman - 12 Jul 2005 21:09 GMT
I think the problem is that VBScript doesn't support named parameters or the
use of the := operator. You'll have to change any statements that use
parameters to pass their values by position. In the case of the PrintOut and
Close methods, the parameters you want to pass are the first on for each
method, so you can just include the value.

Also, unless you define them within the script, VBScript knows nothing about
the values of constants defined in the Word object model. 'False' is the
same in both languages, but you need to use 0 for wdDoNotSaveChanges. I
think you'll be OK with these two lines substituted:

 objWord.ActiveDocument.Printout(False)
 objWord.ActiveDocument.Close(0)

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> I am trying to automate the printing of documents from a specified
> folder on our server.  I am trying to write a VB Script to do this
[quoted text clipped - 35 lines]
> 'Expected Statement' Compile Error on the PrintOut line.  Any help
> would be greatly appreciated.  Thank you.
Thereal Robeen - 15 Jul 2005 15:56 GMT
Thanks Jay, that worked perfectly.

> I think the problem is that VBScript doesn't support named parameters or the
> use of the := operator. You'll have to change any statements that use
[quoted text clipped - 49 lines]
> > 'Expected Statement' Compile Error on the PrintOut line.  Any help
> > would be greatly appreciated.  Thank you.
 
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.