Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.newusers
|
|||
|
|||
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
Posted to microsoft.public.word.newusers
|
|||
|
|||
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
Posted to microsoft.public.word.newusers
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do I set up a tab order without a macro? | Microsoft Word Help | |||
Vertical Label order, any way NOT macro? | Mailmerge | |||
Setting the order of printout in a mail merge | Mailmerge | |||
How to write Macro in Word? | Microsoft Word Help | |||
MS WORD setting the tab order using a single onexit macro | Microsoft Word Help |