Problem: Process all files and directory and save as .xls

larus

New Member
Joined
Apr 4, 2008
Messages
20
Hello,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
I'm trying to process all my .csv files in directory using VBA Marco. My intention is to process all files and save them (with the same file names) into another directory as .xls. The problem is that saving as .xls does not work. My macro looks like this
<o:p></o:p>
<o:p>
Rich (BB code):
Sub ProcessAllFiles()<o:p></o:p>
  Dim sFile As String<o:p></o:p>
  Const sPath As String = "C:\Temp\Excel\"<o:p></o:p>
<o:p></o:p>
  sFile = Dir(sPath & "*.csv")<o:p></o:p>
  <o:p></o:p>
  Do While sFile <> ""<o:p></o:p>
<o:p></o:p>
      Workbooks.Open (sPath & sFile)<o:p></o:p>
      result = ActiveWorkbook.Name<o:p></o:p>
  <o:p></o:p>
      Call Modifaction_macro<o:p></o:p>
  <o:p></o:p>
      ActiveWorkbook.SaveAs _<o:p></o:p>
      Filename:="C:\Temp\Excel\Processed\" + result + ".xls", _<o:p></o:p>
      FileFormat:=xlWorkbookNormal<o:p></o:p>
<o:p></o:p>
  <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:place w:st="on">Loop</st1:place><o:p></o:p>
End Sub<o:p></o:p>
</o:p>Your help is much appreciated<o:p></o:p>
<o:p></o:p>
Larus<o:p></o:p>
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi
try these modifications
Code:
Sub ProcessAllFiles()
  Dim sFile As String
  Const sPath As String = "C:\Temp\Excel\"<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
  sFile = Dir(sPath & "*.csv")
    Do While sFile <> ""
      Workbooks.Open (sPath & sFile)
      result = ActiveWorkbook.Name
     Call Modifaction_macro       
ActiveWorkbook.SaveAs _
      Filename:="C:\Temp\Excel\Processed\" + result, _
      FileFormat:=xlWorkbookNormal
ActiveWorkbook.Close True
sFile = Dir()
  Loop
End Sub
This will loop through all csv files, open them run the called macro and saves the file into different folder as .xls
RAvi
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top