LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default How do you run a macro on all files in a directory?

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!

 
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 - Open all word files in a directory Dileep Chandran Excel Worksheet Functions 11 December 19th 06 02:12 PM
Seeking help with MACRO or VBA??? Open all files of type in directory and parse LeeHarris Excel Programming 1 November 2nd 06 11:25 AM
Macro to move files from one directory to another Barb Reinhardt Excel Programming 0 June 21st 06 05:33 PM
Macro to enumerate subdirs and files in a directory! bookworm98[_9_] Excel Programming 3 January 27th 04 07:48 AM
run macro for all files in the directory igor Excel Programming 3 July 17th 03 03:48 PM


All times are GMT +1. The time now is 07:19 PM.

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"