Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.newusers
Robert Macy Robert Macy is offline
external usenet poster
 
Posts: 2
Default How do I write the macro to put the printout in order?

I have over 100+ documents in a folder and need to print them out from
time to time. I use a macro to print them, but alas the macro follows
the sequence buried in some old DOS structure, or something. The
documents print out in an order only in sections so I have to collate
the whole bundle after printing, a big hassle.

Is there some way to write the macro to have the documents print in
alphabetical order?

Robert
  #2   Report Post  
Posted to microsoft.public.word.newusers
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default How do I write the macro to put the printout in order?

The following macro should print out the contents of a folder in order. Make
sure that only the documents to be printed are in the folder before running
the macro. The documents are not changed or saved in the process.

Sub BatchPrint()
Dim strFileName As String
Dim strPath As String
Dim oDoc As Document
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)

With fDialog
.Title = "Select folder and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show -1 Then
MsgBox "Cancelled By User", , _
"List Folder Contents"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) "\" _
Then strPath = strPath + "\"
End With

If Documents.Count 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
If Left(strPath, 1) = Chr(34) Then
strPath = Mid(strPath, 2, Len(strPath) - 2)
End If
strFileName = Dir$(strPath & "*.doc")

While Len(strFileName) 0
Set oDoc = Documents.Open(strPath & strFileName)
'Do what you want with oDoc
oDoc.PrintOut
oDoc.Close SaveChanges:=wdDoNotSaveChanges
strFileName = Dir$()
Wend
End Sub

http://www.gmayor.com/installing_macro.htm


--

Graham Mayor - Word MVP

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




Robert Macy wrote:
I have over 100+ documents in a folder and need to print them out from
time to time. I use a macro to print them, but alas the macro follows
the sequence buried in some old DOS structure, or something. The
documents print out in an order only in sections so I have to collate
the whole bundle after printing, a big hassle.

Is there some way to write the macro to have the documents print in
alphabetical order?

Robert



  #3   Report Post  
Posted to microsoft.public.word.newusers
Robert Macy Robert Macy is offline
external usenet poster
 
Posts: 2
Default How do I write the macro to put the printout in order?

On May 4, 10:15*pm, "Graham Mayor" wrote:
The following macro should print out the contents of a folder in order. Make
sure that only the documents to be printed are in the folder before running
the macro. The documents are not changed or saved in the process.

Sub BatchPrint()
Dim strFileName As String
Dim strPath As String
Dim oDoc As Document
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)

With fDialog
* * .Title = "Select folder and click OK"
* * .AllowMultiSelect = False
* * .InitialView = msoFileDialogViewList
* * If .Show -1 Then
* * * * MsgBox "Cancelled By User", , _
* * * * "List Folder Contents"
* * * * Exit Sub
* * End If
* * strPath = fDialog.SelectedItems.Item(1)
* * If Right(strPath, 1) "\" _
* * Then strPath = strPath + "\"
End With

If Documents.Count 0 Then
* * Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
If Left(strPath, 1) = Chr(34) Then
* * strPath = Mid(strPath, 2, Len(strPath) - 2)
End If
strFileName = Dir$(strPath & "*.doc")

While Len(strFileName) 0
* * Set oDoc = Documents.Open(strPath & strFileName)
* * 'Do what you want with oDoc
* * oDoc.PrintOut
* * oDoc.Close SaveChanges:=wdDoNotSaveChanges
* * strFileName = Dir$()
Wend
End Sub

http://www.gmayor.com/installing_macro.htm

--

Graham Mayor - *Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org




Robert Macy wrote:
I have over 100+ documents in a folder and need to print them out from
time to time. *I use a macro to print them, but alas the macro follows
the sequence buried in some old DOS structure, or something. *The
documents print out in an order only in sections so I have to collate
the whole bundle after printing, a big hassle.


Is there some way to write the macro to have the documents print in
alphabetical order?


Robert- Hide quoted text -


- Show quoted text -


wow! Thank you for your detailed reply.

I only used a simple form like


Sub ListDocNamesInFolder()
Dim sMyDir As String
Dim sDocName As String
' The path to obtain the files.
sMyDir = "C:\My Documents\TestFolder\"
sDocName = Dir(sMyDir & "*.DOC")
While sDocName ""
' Print the file.
Application.PrintOut FileName:=sMyDir & sDocName
' Get next file name.
sDocName = Dir()
Wend
End Sub


And then, each time I had to reload the macro.

Great website, enjoyed the Ireland photos.

Thank you again. Will try to go through the teps to make the macro
'permanent' too.

Regards,
Robert
Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I set up a tab order without a macro? Nikkita Microsoft Word Help 1 June 8th 08 01:48 PM
Vertical Label order, any way NOT macro? Maharet Mailmerge 1 February 21st 08 05:35 AM
Setting the order of printout in a mail merge ragnar Mailmerge 2 February 10th 07 05:14 AM
How to write Macro in Word? Khoshravan Microsoft Word Help 20 June 4th 06 06:23 AM
MS WORD setting the tab order using a single onexit macro Steve Microsoft Word Help 0 May 7th 06 11:04 PM


All times are GMT +1. The time now is 07:56 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"