Thank you Nikos,
I tried the code below but I now get a "Next without For" error message.
Any idea what I need to do to fix it?
Thank you for your help,
Art.
> See if this works for you:
>
[quoted text clipped - 20 lines]
> HTH,
> Nikos
>>Hello,
>>
[quoted text clipped - 13 lines]
>>
>>Art.
Nikos Yannacopoulos - 20 Oct 2006 09:13 GMT
Art,
Yes, I do have an idea! My mistake (always a problem with untested
code), and a typical misleading error message: the nessage should
actually be "If without End If". I omitted the End If, the code should be:
Sub Process_All_Workbooks()
Dim fs, f, f1
Dim strFile As String
fldr = "C:\SomeFolder" 'Put your folder path here
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(fldr)
Set f1 = f.Files
i = 0
Application.ScreenUpdating = False
For Each f2 In f1
strFile = fldr & f2.Name
If Right(strFile, 4) = ".xls" Then
Workbooks.Open strFile
'Code to do what you want here
'Possibly calling the other macro?
ActiveWorkbook.Close , True
End If
Next
Application.ScreenUpdating = True
End Sub
Hope it works this time!
Nikos
Art MacNeil - 21 Oct 2006 01:32 GMT
Brilliant!!
It works like a charm. I do have one other request.
Is there a way to automatically save the spreadsheets/workbooks? There are
times when I update 200 spreadsheets/workbooks. Also I'd like to have a way
to not save the changes because there are times when I'll run a Macro on a
bunch of spreadsheets/workbooks but don't want them saved.
Is this possible?
Thanks again,
Art.
> Art,
>
[quoted text clipped - 25 lines]
> Hope it works this time!
> Nikos
Art MacNeil - 21 Oct 2006 01:48 GMT
I added a ActiveWorkbook.Save line to my Macro so now I don't get the "Do
you want to save the changes you made..." error message. However, I'd like
to find a way to select "No" to the "Do you want to save the changes you
made..." error message.
Thanks,
Art.
> Brilliant!!
>
[quoted text clipped - 40 lines]
>> Hope it works this time!
>> Nikos
Dave Peterson - 21 Oct 2006 04:53 GMT
Activeworkbook.close savechanges:=false
If you've already saved your changes.
> I added a ActiveWorkbook.Save line to my Macro so now I don't get the "Do
> you want to save the changes you made..." error message. However, I'd like
[quoted text clipped - 49 lines]
> >> Hope it works this time!
> >> Nikos

Signature
Dave Peterson
Art MacNeil - 21 Oct 2006 06:00 GMT
That did the job.
Thank you Nikos and Dave.
Art.
> Activeworkbook.close savechanges:=false
>
[quoted text clipped - 56 lines]
>> >> Hope it works this time!
>> >> Nikos
Art MacNeil - 21 Oct 2006 06:28 GMT
If anyone else is looking for a way to open multiple workbooks and run
another macro on each of them, you can use the following:
Credit to Nikos Yannacopoulos and Dave Peterson for making this Macro as
good as it is.
If you want to save your changes use "True" at the "ActiveWorkbook.Close
savechanges" line.
If you don't want those changes saved, use "False" at the
"ActiveWorkbook.Close savechanges" line.
Here's the code:
Dim fs, f, f1
Dim strFile As String
fldr = "C:\Test Area\" 'Put your folder path here
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(fldr)
Set f1 = f.Files
i = 0
Application.ScreenUpdating = False
For Each f2 In f1
strFile = fldr & f2.Name
If Right(strFile, 4) = ".xls" Then
Workbooks.Open strFile
Call Macro1 'Call another macro or write code to do what you want here.
ActiveWorkbook.Close savechanges:=True 'Change accordingly.
True will save the spreadsheet and False will not.
End If
Next
Application.ScreenUpdating = True
End Sub
Thank you guys,
Art.
> Activeworkbook.close savechanges:=false
>
[quoted text clipped - 56 lines]
>> >> Hope it works this time!
>> >> Nikos