View Single Post
  #3   Report Post  
Posted to microsoft.public.word.docmanagement
#DIV/0 #DIV/0 is offline
external usenet poster
 
Posts: 7
Default Print all documents AND run a macro

I'm sorry I didn't see yesterday's post (although the code is similar the
query was about saving as pdf not printing so I think I can be forgiven).
I'd got as far as getting to the end of the doc, inserting the filename and
closing without saving - the easy part - I just couldn't figure out how to
get the folder contents into an array that I could then address.
Thanks a million - we have nearly a thousand docs and about half of them are
out of date. Now I can print them all, show them to the technicians and when
they say "no good - delete it" I don't have to spend hours opening random
files trying to find the bad one.

--
David M


"Graham Mayor" wrote:

This is almost the same requirement for which I posted a solution
yesterday -

Sub PrintWithAddedNames()
On Error GoTo err_FolderContents
Dim FirstLoop As Boolean
Dim DocList As String
Dim DocDir As String

With Dialogs(wdDialogCopyFile)
If .Display 0 Then
DocDir = .Directory
Else
MsgBox "Cancelled by User"
Exit Sub
End If
End With
If Documents.Count 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
Application.ScreenUpdating = False
FirstLoop = True
If Left(DocDir, 1) = Chr(34) Then
DocDir = Mid(DocDir, 2, Len(DocDir) - 2)
End If
DocList = Dir$(DocDir & "*.doc")
Do While DocList ""
Documents.Open DocList
Selection.EndKey Unit:=wdStory
Selection.TypeText vbCr & ActiveDocument.FullName
ActiveDocument.PrintOut
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
DocList = Dir$()
FirstLoop = False
Loop
Application.ScreenUpdating = True
Exit Sub
err_FolderContents:
MsgBox Err.Description
Exit Sub
End Sub

The macro will prompt for the folder then will open each *.doc in that
folder, add the filename and path to the bottom, print to the current active
printer then close without saving. It would be advisable to test with a
folder containing only one document to ensure it gives the required results.


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


#DIV/0 wrote:
Hi,
I've found the print-all-documents on the MVPS site but I want more!
:-)
For every document in a specific folder I need to:
- open each file and put the filename (with path) on the bottom line
- print the doc
- close it without saving the changes