View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Jim May Jim May is offline
external usenet poster
 
Posts: 477
Default Macro to Print All Files in a Folder

Bob: Thanks for looking in on this..
What I was trying to do << and have since accomplished-below was:
using what i call a surrogate workbook to run a macro which opens
each .xls file in a folder and prints each and then closes each. The code
I posted was printing my surrogate activesheet twice since my test folder had two files in it..
I later found this code by Ron de Bruin off google.. [works perfectly]

Sub PrintAllinFolder()
Dim i As Long
Dim WB As Workbook
Application.ScreenUpdating = False
With Application.FileSearch
.NewSearch
.LookIn = "C:\WINDOWS\Desktop\Temp Excel Formulas\Backuptest"
.SearchSubFolders = False
.FileType = msoFileTypeExcelWorkbooks
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
Set WB = Workbooks.Open(.FoundFiles(i))
WB.PrintOut
WB.Close False
Next i
End If
End With
Application.ScreenUpdating = True
End Sub



"Bob Phillips" wrote:

Jim,

What is that you want that you don't get? It may seem obvious, but I tried
this with my directory and it worked fine for me.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Jim May" wrote in message
news:SeuKc.374$ci.127@lakeread04...
Off google I found the following code, which I have since modified to
accomplish my subject objective; <<to no avail can someone assist?

Sub Tester9()
PathOnlysource = "C:\Formulas\Backuptest"
ChDir PathOnlysource
TheFile = Dir(PathOnlysource & "\*.xls")
Do While TheFile < ""
ActiveSheet.PrintOut
TheFile = Dir
Loop
End Sub