V
vidguru
I have searched this board over and over and can't find what I need to
do. I have created a macro called Joe. What it does is insert
columns, create worksheets, and a pivot table. If I need to post the
code, I will, not a problem. I am having a problem finding a code to
add to this to get it to run for all xls files in the directory, save,
and close. I have looked at many I have found here, and can't adopt
anything to get it to work. Is there any basic/generic code that can
be used? I was hopeful I could use this one:
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
And replace the lines that say Range with my macro, no luck. There are
several other macro's that I will need to run throughout the quarter on
all files in the directory so if there is some basic macro I can use
and just copy and paste my macro in, it would be very nice.
Thank You!
do. I have created a macro called Joe. What it does is insert
columns, create worksheets, and a pivot table. If I need to post the
code, I will, not a problem. I am having a problem finding a code to
add to this to get it to run for all xls files in the directory, save,
and close. I have looked at many I have found here, and can't adopt
anything to get it to work. Is there any basic/generic code that can
be used? I was hopeful I could use this one:
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
And replace the lines that say Range with my macro, no luck. There are
several other macro's that I will need to run throughout the quarter on
all files in the directory so if there is some basic macro I can use
and just copy and paste my macro in, it would be very nice.
Thank You!