• Auto Print Word Doc (XP; 2002 SP3)

    Author
    Topic
    #442508

    I have a CD full of MS Word files [1,427 doc files]. My assignment is to print each document. Which is looking like a manual proposition.

    Is there a way to have MS Word loop through the various directories until it reaches the end of the CD and open, print and then close each document? I am also struggling with how to determine when the end of the CD is reached….[how to discern EOF and end my loop].

    I also wondered if I should try a batch file to use MS word’s print capability without firing up MS Word itself. This would seem to be “faster” than MS word opening and closing each of 1,427 doc files. But I can’t seem to find anything on the interenet about this–perhaps it is because I am not sure which search words to use. Can MS Word XP be manipulated from a command line prompt or batch file? Or should I continue to try to develop VBA code in MS Word to do what I want [open, print and close each doc file]?

    Any guidance is welcome….THANKS.

    Viewing 0 reply threads
    Author
    Replies
    • #1065364

      You could use FileSearch to find all Word documents on the CD. The following macro is to be run from within Word. Change the constant strPath at the beginning as needed.

      Sub PrintFolder()
      ‘ Highest level folder you want to search
      Const strPath = “E:”
      ‘ Loop counter
      Dim i As Integer
      ‘ Doc variable
      Dim doc As Document
      With Application.FileSearch
      .FileType = msoFileTypeWordDocuments
      .LookIn = strPath
      .Execute
      .SearchSubFolders = True
      For i = 1 To .FoundFiles.Count
      Application.StatusBar = “Processing ” & .FoundFiles(i)
      Set doc = Documents.Open( _
      FileName:=.FoundFiles(i), _
      AddToRecentFiles:=False)
      doc.PrintOut Background:=False
      doc.Close SaveChanges:=False
      Next i
      End With
      Application.StatusBar = “”
      End Sub

      Note: Word docs cannot be printed without Word. Even if you right-click a document in Windows Explorer and select Print, Word is started to print the document and then closed again.

      • #1065414

        Hans,
        Thanks for the code–it worked as always. I do have a question though..what does the last line in your code do [Application.StatusBar=””]? Assume this suppresses the statusbar screen updates to speed up the code? Or am I totally off base? I was going to remove it and run the macro…but then I remembered that I am at work and didn’t want to hose my work pc and face the wrath of the “system administrator”….

        Also, I am getting the code to stop with a MS Word dialog box stating that the margins of section 1 are set outside the printable area of the page, Do you want to continue?” I had so many of these messages, that I stopped the operation of the code to investigate…

        I understand the message–but am not sure why a few of the files are prompting and most are not. All of the Word files came from the same client PC…which uses the same HP laserjet printer. I am also printing to an HP laserjet albeit a different model number. When I click “yes” to continue the file prints…and everything on the printout is fine—I have the footer, etc. nothing seems to be missing. So I am baffled as to the “cause” of the abnormality in the doc files and why it still seems to print ok.

        I have learned alot about reading the Word help file and google information on margins…but none of this information seems to help me solve the issue. Can I even discern which .doc files will have a margin issue via macro code? My fear too is what happens if I click yes and in reality something does not print out—I will never know this—unless I compare every hardcopy to the screen. Yikes!

        My goal was to run the macro at the end of the day when most people are gone so that I am not chastised for excessive usage of the network printer…I was also hoping that the macro could run unattended [i.e. I could go home ] given the number of .doc files to process—-all that seems to be a dream given the dialog box prompt for margins on one out of every 7 or 8 files and that how can I “really” know that everything does print?

        Any ideas? Thanks again for your willingness to share your talents…If I ever get to know 5% of what you know…I’ll feel good, no make that I’ll feel GREAT. Take care. smile

        • #1065425

          I put a line

          Application.StatusBar = “Processing ” & .FoundFiles(i)

          inside the loop to keep you informed of which file is being printed. The line

          Application.StatusBar = “”

          simply clears the status bar. Both lines can be deleted without any problem.

          Different printer models have different non-printable areas, so if the margins are OK for one printer, they may be out of bounds for another one. You may be able to suppress the prompts by inserting

          Application.DisplayAlerts = False

          at the beginning of the macro, and

          Application.DisplayAlerts = True

          at the end.

          • #1065427

            Hans,
            I will try this tomorrow as I have will need to work on Saturday anyway…and won’t be chastised for excessive printer use…I’ll experiment further with your code. Thank you for the explanation…I really do appreciate it and when I search for information in the lounge…it is often your explanation in plain terms on your posts that helps me greatly–so much so that I may not need to post a question myself on that topic in that you explained the issue so clearly I can finish my projects. Again, many thanks!! Have a nice weekend.

    Viewing 0 reply threads
    Reply To: Auto Print Word Doc (XP; 2002 SP3)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: