Connecting Tech Pros Worldwide Help | Site Map

Print all files in folder Macro

  #1  
Old July 3rd, 2009, 11:28 AM
Member
 
Join Date: Feb 2007
Posts: 43
I am trying to write a macro that will print all files in a particular folder. The folder will always have the same name - but the number of files in that folder may differ. I simply want a macro that will open and print all the files in the specified folder (D:\TEST) and then close each file down. I've got so far but I get a subscript out of range on the line with a * next to it. I am no expert on this so it may be easier to rewrite than fix this!

Any help would be greatly appreciated!
thanks

Sub BatchMacro()
Dim oDoc As Workbook
Dim sPath As String
Dim sFileSpec As String
Dim sFile As String
Dim sFileList() As String
Dim i As Integer

' Get Folder
'sPath = InputBox("Enter Word Doc Folder to Process", "Batch", "")
sPath = "D:/TEST"
' Clean up


' Add Word extention
sFileSpec = sPath & "*.xls"

' Get All filenames in the Folder
sFile = Dir$(sFileSpec)

i = -1
Do Until sFile = ""
i = i + 1
ReDim Preserve sFileList(i) As String
sFileList(i) = sFile
sFile = Dir$
Loop

' Process each file
For i = 0 To UBound(sFileList)* problem line
Set oDoc = Workbooks.Open(sPath & sFileList(i))


ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True


Call oDoc.Close(True)
Next i

' Release dynamic array
Erase sFileList

'
End Sub
  #2  
Old July 3rd, 2009, 11:46 AM
Member
 
Join Date: Feb 2007
Posts: 43

re: Print all files in folder Macro


Sorted it! I had forgotten to put the / at the end of the folder path!!!!!!!!!
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Linked tables in MS Access 2003 Airtech answers 7 August 20th, 2009 06:25 PM
Re: extract from zip files.. crashonyou answers 11 October 27th, 2007 02:02 PM
Excel VBA set active document joemo2003 answers 6 May 7th, 2007 03:09 PM
How to access PDF files?? Richard answers 2 November 21st, 2005 09:24 PM