Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

URGENT :  I have a thousand or so Docs to print ..

Posted on 2006-05-07
8
Medium Priority
?
216 Views
Last Modified: 2010-04-07
I have a thousand or so documents to print that have been created in MS Word. The documents have varying lengths, some 1 5 pages otheres up to 4400 pages.

I would like to build a routine that take a file, prints it and dumps the fill into another directory ... my skills are poor so full coded and commented code is appreciated ....

Regards


Darrin
0
Comment
Question by:dwe0608
  • 3
5 Comments
 
LVL 33

Expert Comment

by:Robberbaron (robr)
ID: 16625104
cant fully test right now but this is an adaptation of something i did before

'------------------8<--------------------------
dim sLogFolder , oFSO, oFolder, oFile , cFilesLIst
dim sLogFiles , sTagCode , sCSVname , oCSVFile , sResultLine

sLogFolder="C:\work\ee"
sLogFiles="doc"


'search the Logfolder for .log files


'open each log file
'  load each line.  (or load the entire file as string)
'    check for tagcode
'    if tagcode exists, write data to CSV
'  next line
'next file

    Set WshShell = CreateObject("WScript.Shell")
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set oFolder = oFSO.GetFolder(sLogFolder)
      
    Set cFilesList = oFolder.Files
    For Each oFile in cFilesList
      If oFSO.GetExtensionName(oFile.name)=sLogFiles then
      fullname=sLogFiles & "\" & oFile.name
      movename=sLogFiles & "\done\" & oFile.name
      sCommand="C:\Program Files\Microsoft Office\Office\winword.exe " & fullname & " /mFilePrintDefault "

      'print the document
      x=WshShell.Run (strCommand, 7, true)
            

      oFSO.MoveFile fullname , movename
      End if
    Next


    oCSVFile.Close
    set FSO=nothing

'----------------:<-------------
0
 
LVL 33

Expert Comment

by:Robberbaron (robr)
ID: 16625141
1. update --- need to add quotes around command line string...
2. but also see http://support.microsoft.com/?kbid=201993  WD2000: Sample Macro to Print All Word Documents Found in a Folder

should be able to modify the MS script to move done files to a subfolder.....

'----------:<-------------------

dim sLogFolder , oFSO, oFolder, oFile , cFilesLIst
dim sLogFiles , sTagCode , sCSVname , oCSVFile , sResultLine

sLogFolder="C:\work\ee"
sLogFiles="doc"



    Set WshShell = CreateObject("WScript.Shell")
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set oFolder = oFSO.GetFolder(sLogFolder)
      
    Set cFilesList = oFolder.Files
       sQt=chr(34)
    For Each oFile in cFilesList
      If oFSO.GetExtensionName(oFile.name)=sLogFiles then
      fullname=sLogFolder & "\" & oFile.name
      movename=sLogFolder & "\done\" & oFile.name
      sCommand= sQt & "C:\Program Files\Microsoft Office\Office\winword.exe" & sQt & " " & sQt & fullname & sQt & " /mFilePrintDefault "

      
      'print the document
      'wscript.echo sCommand

      x = WshShell.Run (SCommand,7,true)



      oFSO.MoveFile fullname , movename
      End if

    Next

    set FSO=nothing
'----------------------:<-------------------------------
0
 
LVL 77

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 16626013
This way uses Word directly to do the print.

You need to set a reference (via Project/References...) to the Microsoft Word Object library

Private Sub Command2_Click()
    Dim wdDoc As Word.Document
    Dim wdApp As Word.Application
    Dim strFile As String
   
    Const strFolder = "C:\Docs1\"
    Const strNewFolder = "C:\Docs2\"
   
    Set wdApp = New Word.Application 'create a new Word applicaion
    wdApp.Visible = True 'make it visible in case macro aborts & WinWord is left in task list
    strFile = Dir$(strFolder & "*.Doc") ' find first file in folder
    Do Until strFile = ""
        Set wdDoc = wdApp.Documents.Open(strFolder & strFile) 'open it in Word
        wdDoc.PrintOut 'print it through Word
        wdDoc.Close False 'c;lose withot saving
        Name strFolder & strFile As strNewFolder & strFile 'move to a new folder
        strFile = Dir$() 'get next document name
    Loop
    wdApp.Quit 'stop this Word instance
End Sub
0
 
LVL 33

Expert Comment

by:Robberbaron (robr)
ID: 16626983

the code sample by Microsoft & GrahamScan version are best as my one only prints each document , leaving Word open to be closed manually. Not good!

The MS one is best suited for running within Word.

Interesting to see if

wdApp.PrintOut Filename:= strFolder & StrFile

would work in place of Open , PrintOut , Close steps in VB code.
0
 
LVL 1

Author Comment

by:dwe0608
ID: 16648023
I am giving a try to each of the methods sugested and will pop back to award points in the next s=day or so
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question