Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Open all workbooks inside a folder, run macro and save them?

Hi,

I have a folder that has more than 400 excel files, and all of them contain
unformatted data. I have a macro for formatting this data that runs as
required. The problem is I need to open each file individually and run the
macro to format the data in each file.

So is there a way I can open all the workbooks inside the folder, run the
macro that I have already for all of them, and then save the workbook? the
data is contained in Sheet 1 in all the workbooks.

Thanks :)


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Open all workbooks inside a folder, run macro and save them?


Sub LoopFolders()
Dim oFSODim Folder As Object
Dim Files As Object
Dim file As Object

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set Folder = oFSO.GetFolder("c:\MyTest")

For Each file In Folder.Files
If file.Type Like "*Microsoft Excel*" Then
Workbooks.Open Filename:=file.Path
'<<<<< run macro here on Activeworkbook
Activeworkbook.Close SaveChanges:=False
End If
Next file
Set oFSO = Nothing

End Sub



--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Pman" wrote in message
...
Hi,

I have a folder that has more than 400 excel files, and all of them
contain
unformatted data. I have a macro for formatting this data that runs as
required. The problem is I need to open each file individually and run the
macro to format the data in each file.

So is there a way I can open all the workbooks inside the folder, run the
macro that I have already for all of them, and then save the workbook? the
data is contained in Sheet 1 in all the workbooks.

Thanks :)




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Open all workbooks inside a folder, run macro and save them?

Thanks for the quick reply Bob, but when I run the macro I get an error
message, and the text "Dim oFSODim Folder As Object" is highlighted when I go
into De-bug mode.

When I run the LoopFolders macro, do I have to open my 1st workbook and run
the macro in it?

Thanks,

Peter.

"Bob Phillips" wrote:


Sub LoopFolders()
Dim oFSODim Folder As Object
Dim Files As Object
Dim file As Object

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set Folder = oFSO.GetFolder("c:\MyTest")

For Each file In Folder.Files
If file.Type Like "*Microsoft Excel*" Then
Workbooks.Open Filename:=file.Path
'<<<<< run macro here on Activeworkbook
Activeworkbook.Close SaveChanges:=False
End If
Next file
Set oFSO = Nothing

End Sub



--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Pman" wrote in message
...
Hi,

I have a folder that has more than 400 excel files, and all of them
contain
unformatted data. I have a macro for formatting this data that runs as
required. The problem is I need to open each file individually and run the
macro to format the data in each file.

So is there a way I can open all the workbooks inside the folder, run the
macro that I have already for all of them, and then save the workbook? the
data is contained in Sheet 1 in all the workbooks.

Thanks :)





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Open all workbooks inside a folder, run macro and save them?

That should be two lines:
Dim oFSO
Dim Folder As Object



Pman wrote:

Thanks for the quick reply Bob, but when I run the macro I get an error
message, and the text "Dim oFSODim Folder As Object" is highlighted when I go
into De-bug mode.

When I run the LoopFolders macro, do I have to open my 1st workbook and run
the macro in it?

Thanks,

Peter.

"Bob Phillips" wrote:


Sub LoopFolders()
Dim oFSODim Folder As Object
Dim Files As Object
Dim file As Object

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set Folder = oFSO.GetFolder("c:\MyTest")

For Each file In Folder.Files
If file.Type Like "*Microsoft Excel*" Then
Workbooks.Open Filename:=file.Path
'<<<<< run macro here on Activeworkbook
Activeworkbook.Close SaveChanges:=False
End If
Next file
Set oFSO = Nothing

End Sub



--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Pman" wrote in message
...
Hi,

I have a folder that has more than 400 excel files, and all of them
contain
unformatted data. I have a macro for formatting this data that runs as
required. The problem is I need to open each file individually and run the
macro to format the data in each file.

So is there a way I can open all the workbooks inside the folder, run the
macro that I have already for all of them, and then save the workbook? the
data is contained in Sheet 1 in all the workbooks.

Thanks :)






--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Open all workbooks inside a folder, run macro and save them?

Thanks Bob :)

"Bob Phillips" wrote:


Sub LoopFolders()
Dim oFSODim Folder As Object
Dim Files As Object
Dim file As Object

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set Folder = oFSO.GetFolder("c:\MyTest")

For Each file In Folder.Files
If file.Type Like "*Microsoft Excel*" Then
Workbooks.Open Filename:=file.Path
'<<<<< run macro here on Activeworkbook
Activeworkbook.Close SaveChanges:=False
End If
Next file
Set oFSO = Nothing

End Sub



--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Pman" wrote in message
...
Hi,

I have a folder that has more than 400 excel files, and all of them
contain
unformatted data. I have a macro for formatting this data that runs as
required. The problem is I need to open each file individually and run the
macro to format the data in each file.

So is there a way I can open all the workbooks inside the folder, run the
macro that I have already for all of them, and then save the workbook? the
data is contained in Sheet 1 in all the workbooks.

Thanks :)







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Open all workbooks inside a folder, run macro and save them?

Thanks Dave :)

"Dave Peterson" wrote:

That should be two lines:
Dim oFSO
Dim Folder As Object



Pman wrote:

Thanks for the quick reply Bob, but when I run the macro I get an error
message, and the text "Dim oFSODim Folder As Object" is highlighted when I go
into De-bug mode.

When I run the LoopFolders macro, do I have to open my 1st workbook and run
the macro in it?

Thanks,

Peter.

"Bob Phillips" wrote:


Sub LoopFolders()
Dim oFSODim Folder As Object
Dim Files As Object
Dim file As Object

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set Folder = oFSO.GetFolder("c:\MyTest")

For Each file In Folder.Files
If file.Type Like "*Microsoft Excel*" Then
Workbooks.Open Filename:=file.Path
'<<<<< run macro here on Activeworkbook
Activeworkbook.Close SaveChanges:=False
End If
Next file
Set oFSO = Nothing

End Sub



--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Pman" wrote in message
...
Hi,

I have a folder that has more than 400 excel files, and all of them
contain
unformatted data. I have a macro for formatting this data that runs as
required. The problem is I need to open each file individually and run the
macro to format the data in each file.

So is there a way I can open all the workbooks inside the folder, run the
macro that I have already for all of them, and then save the workbook? the
data is contained in Sheet 1 in all the workbooks.

Thanks :)






--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to open, Update links, save and close workbooks Anton Excel Discussion (Misc queries) 0 January 7th 10 03:18 AM
open all workbooks in a folder Amit Excel Programming 3 April 21st 07 05:52 AM
open file from folder save in new folder tim64[_3_] Excel Programming 20 June 17th 05 07:58 PM
Macro to Open all workbooks in a folder and change default font Carlton A. Barlow Excel Programming 1 October 15th 04 01:38 PM
Using VBA in Excel to Make a Folder to Save Workbooks in Jeff Marshall[_2_] Excel Programming 2 September 22nd 03 08:36 PM


All times are GMT +1. The time now is 02:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"