473,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Print all files in folder Macro

63
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
Jul 3 '09 #1
1 3770
grego9
63
Sorted it! I had forgotten to put the / at the end of the folder path!!!!!!!!!
Jul 3 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jeff Marcum | last post by:
I have a database set-up to do file comparisons. I import the files into the database and do the comparisons with queries. I have to do this comparison on a daily basis so I would like to set up...
1
by: RFS | last post by:
how do I get the path to the Program Files folder?
3
by: Rajiv Das | last post by:
VS 2003, XP SP2 ------------------------------------------------------------ DirectoryInfo temporary = new DirectoryInfo( Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));...
5
by: Roy | last post by:
My dll file is copied to the "%windir%\Microsoft.NET\Framework\{version}Temporary ASP.NET Files" folder when I compile my asp.net project. When I run the application. The dll under this folder is...
6
by: 2112 | last post by:
I'm compiling a dll that imports msado15.dll. When I'm using Windows in English, the msado15.dll is located at <drive>:\Program Files\Common Files\System\ADO\msado15.dll". When using Windows in...
0
by: studentintau | last post by:
I would thank you if you help me with the next subject : how do i copy all files from temporary internet files folder to another folder in drive D?
5
by: Warren Tang | last post by:
Hi I am trying to debug the code generated for aspx files. The following assembly is generated for an aspx page: ...
0
by: bharris | last post by:
Is there a simple way to print files stored in an OLE field using the Windows associated programs? So if it is a .doc, it will open Word, print it and close. PDF opens Acrobat Reader, prints and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.