View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_5_] Dave Peterson[_5_] is offline
external usenet poster
 
Posts: 1,758
Default Batching files through a macro

One way:

Option Explicit
Sub testme01()

Dim tempWkbk As Workbook

Dim myNames() As String
Dim fCtr As Long
Dim myFile As String
Dim myPath As String

'change to point at the folder to check
myPath = "C:\my documents\excel\test"
If Right(myPath, 1) < "\" Then
myPath = myPath & "\"
End If

myFile = Dir(myPath & "*.xls")
If myFile = "" Then
MsgBox "no files found"
Exit Sub
End If

'get the list of files
fCtr = 0
Do While myFile < ""
fCtr = fCtr + 1
ReDim Preserve myNames(1 To fCtr)
myNames(fCtr) = myFile
myFile = Dir()
Loop

If fCtr 0 Then

For fCtr = LBound(myNames) To UBound(myNames)
Set tempWkbk = Workbooks.Open(Filename:=myPath & myNames(fCtr))

'your macro that does the work goes
here

tempWkbk.Close savechanges:=True

Next fCtr

End If

End Sub

If you have trouble with your code that does the work, post back what you have.

emt29165 wrote:

I have created a macro to modify exported files from a student managament
system into the a format for submission of grades, but I cannot accomplish
two things with my limited knowledge (the macro deletes 3 columns, reorders
what is left, formats one and saves as a csv).

1) How can I batch all of the files through the macro (all in one folder)?

2) How can I save them with their original names?

Thanks in advance for your help!


--

Dave Peterson