Applying a macro to all Excel-files in a folder
One way
Sub ProcessFiles()
Dim i As Long
Dim sFolder As String
Dim fldr As Object
Dim FSO As Object
Dim Folder As Object
Dim file As Object
Dim Files As Object
Dim this As Workbook
Dim cnt As Long
Set FSO = CreateObject("Scripting.FileSystemObject")
Set this = ActiveWorkbook
sFolder = "C:\MyTest"
If sFolder < "" Then
Set Folder = FSO.GetFolder(sFolder)
Set Files = Folder.Files
cnt = 1
For Each file In Files
If file.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=file.Path
With ActiveWorkbook
With .Worksheets(1)
.Range("A16").EntireRow.Insert
.Range("A16").Value = "ABC"
'etc.
End With
.Save
.Close
End With
cnt = cnt + 1
End If
Next file
End If ' sFolder < ""
End Sub
--
HTH
RP
(remove nothere from the email address if mailing direct)
"Louise" wrote in message
...
How do I apply a macro to all excel sheets in a folder? (in my case I need
to
insert a row with certain content in row 16 in 700 excel sheets). All
sheets
are alike.
Thank you!
Louise
|