Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2008

Tip: Looking for answers? Try searching our database.

find files & number of pages then print

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
taylorkand@gmail.com - 06 Feb 2008 14:52 GMT
I am new to word vba and need to write a macro that does the
following:

1. Search folder for word files
2. For each file found count the number of pages
3. If the number of pages is odd, print
4. If the number of pages is even, print, but print 2 pages per sheet

I have gotten it to find the files in the folder with the following
code, but I don't know how to do steps 2, 3,4.  Please help!

Set fs = Application.FileSearch

   With fs
       .LookIn = "E:\*****"
       .FileType = msoFileTypeWordDocuments
       If .Execute > 0 Then
       Let counted = .FoundFiles.Count
       Else
       MsgBox "There were no files found."
       End If
End With
Graham Mayor - 06 Feb 2008 15:28 GMT
The following should work  - try it on a couple of files in a folder before
committing to a large print run ;)

Sub BatchPrint()
On Error GoTo err_FolderContents
Dim FirstLoop As Boolean
Dim DocList As String
Dim DocDir As String
Dim fDialog As FileDialog
Dim intPages As Integer
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)

With fDialog
   .Title = "Select Folder containing the documents to be printed and click
OK"
   .AllowMultiSelect = False
   .InitialView = msoFileDialogViewList
   If .Show <> -1 Then
       MsgBox "Cancelled By User"
       Exit Sub
   End If
   PathToUse = fDialog.SelectedItems.Item(1)
   If Right(PathToUse, 1) <> "\" Then PathToUse = PathToUse + "\"
End With

If Documents.Count > 0 Then
   Documents.Close savechanges:=wdPromptToSaveChanges
End If
Application.ScreenUpdating = False
FirstLoop = True
DocList = Dir$(DocDir & "*.doc")

   Do While DocList <> ""
       Documents.Open DocList
       intPages = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
       If intPages Mod 2 = 0 Then
           ActiveDocument.PrintOut , PrintZoomColumn:=2, PrintZoomRow:=1
       Else
           ActiveDocument.PrintOut
       End If

       ActiveDocument.Close savechanges:=wdDoNotSaveChanges
       DocList = Dir$()
       FirstLoop = False
  Loop

Application.ScreenUpdating = True
Exit Sub
err_FolderContents:
   MsgBox Err.Description
   Exit Sub
End Sub

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

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

> I am new to word vba and need to write a macro that does the
> following:
[quoted text clipped - 18 lines]
>        End If
> End With
taylorkand@gmail.com - 13 Feb 2008 20:50 GMT
Sorry it took so long to respond, boss had more focus on some other
tasks.  Thank you so much though, it works perfectly!

> The following should work  - try it on a couple of files in a folder before
> committing to a large print run ;)
[quoted text clipped - 82 lines]
>
> - Show quoted text -
Graham Mayor - 14 Feb 2008 07:53 GMT
You are welcome :)

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

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

> Sorry it took so long to respond, boss had more focus on some other
> tasks.  Thank you so much though, it works perfectly!
[quoted text clipped - 85 lines]
>>
>> - Show quoted text -
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.