Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default How to run Excel Macro on all files in folder

Dear All,

I have Excel Macro and I want to run on all files in folder and then save
all files. Files are in CSV format.

Kindly write the full procedure step by step.

Thanks in advance.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default How to run Excel Macro on all files in folder

Hi TFMR,

There are loads of code snippets in this group that will tell you how
to do this if you have a look around.

This should get you most of the way.

Sub Open_All_Wbks()
'Open all .csv files in specified directory, refresh the query/save/
close
Dim lCount As Long
Dim wbResults As Workbook
Dim wbCodeBook As Workbook

On Error Resume Next
Set wbCodeBook = ThisWorkbook
With Application.FileSearch
.NewSearch
'Change path to suit
.LookIn = "C:\"
.Filename = "*.csv" 'apply to all .csv files
If .Execute 0 Then 'Workbooks in folder
For lCount = 1 To .FoundFiles.Count 'Loop through all.
'Open Workbook x and Set a Workbook variable to it
'Your code goes here
wbResults.Close savechanges:=True
Next lCount
End If
End With
On Error GoTo 0
End Sub

Cheers,
JF
On 24 Sep, 11:58, TFMR wrote:
Dear All,

I have Excel Macro and I want to run on all files in folder and then save
all files. Files are in CSV format.

Kindly write the full procedure step by step.

Thanks in advance.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default How to run Excel Macro on all files in folder


Sub LoopFolders()
Dim oFSO
Dim Folder As Object
Dim Files As Object
Dim file As Object
Dim fldr

Set oFSO = CreateObject("Scripting.FileSystemObject")

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

For Each file In Folder.Files
If file.Type Like "*Comma Separated*" Then
Workbooks.Open Filename:=file.Path
'do stuff
Activeworkbook.save
Activeworkbook.Close
End If
Next file

Set oFSO = Nothing

End Sub


--
__________________________________
HTH

Bob

"TFMR" wrote in message
...
Dear All,

I have Excel Macro and I want to run on all files in folder and then save
all files. Files are in CSV format.

Kindly write the full procedure step by step.

Thanks in advance.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default How to run Excel Macro on all files in folder

Hi Bob,

There is one more query, that files in CSV format and when I run following
macro then again there is popup which asked you want to save and three option
YES NO Cancel

I want to save all the files continiously without asking again. Remember
that files are in CSV format thats why excel verify. Please help me in that.

Thanks & Regards

TFMR

"Bob Phillips" wrote:


Sub LoopFolders()
Dim oFSO
Dim Folder As Object
Dim Files As Object
Dim file As Object
Dim fldr

Set oFSO = CreateObject("Scripting.FileSystemObject")

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

For Each file In Folder.Files
If file.Type Like "*Comma Separated*" Then
Workbooks.Open Filename:=file.Path
'do stuff
Activeworkbook.save
Activeworkbook.Close
End If
Next file

Set oFSO = Nothing

End Sub


--
__________________________________
HTH

Bob

"TFMR" wrote in message
...
Dear All,

I have Excel Macro and I want to run on all files in folder and then save
all files. Files are in CSV format.

Kindly write the full procedure step by step.

Thanks in advance.





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 rename Excel files in a folder [email protected] Excel Programming 3 January 19th 07 09:59 PM
how can I specific a folder with wildcard criteria and excel will import all the correct files in that folder? Raven[_2_] Excel Programming 1 January 24th 06 04:23 AM
Excel macro to open files within a folder Craig[_24_] Excel Programming 2 October 8th 05 08:28 AM
Macro to copy range from Excel files in folder nc Excel Discussion (Misc queries) 1 June 15th 05 11:11 AM
Applying a macro to all Excel-files in a folder Louise Excel Programming 6 March 22nd 05 02:43 PM


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

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

About Us

"It's about Microsoft Excel"