Thread: Generic Macro
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.misc
WildWill WildWill is offline
external usenet poster
 
Posts: 64
Default Generic Macro

Hi

My bad - I should have given more info on the change that I want to apply to
each file. It goes something like this:

1. Unprotect Sheet X, Y and Z;
2. Move to cell B22 in Sheet X and remove cell protection.
3. Select cells C39 on Sheet Y and delete the comments in those cells;
4. On Sheet Z, insert a cell at line 6 of column C.
5. Now re-apply protection on sheets X, Y and Z,
6. Save changes,
7. Close file.

I need to apply exactly the same routine to all 50 x files.

"Otto Moehrbach" wrote:

Will
This macro should be placed in a regular module of a new blank file, or in
any other file you wish. That file must be placed in the same folder as the
files you want to change. Note that this macro will change EVERY .xls file
in that folder except the file that contains this macro. The names of your
files are not important to this macro. This macro looks at only the file
extensions. Note that this macro does not contain any code to actually
accomplish the changes you want. As written, this macro will only open and
close each file in the folder, in turn. It's up to you to insert the change
code where designated. If you need help with the change code, post back and
detail the changes you want made to each file. Include sheet names, rows,
columns, whatever, as needed to make the changes you want. HTH Otto
Sub AllFolderFiles()
Dim wb As Workbook
Dim TheFile As String
Dim MyPath As String
MyPath = ThisWorkbook.Path
ChDir MyPath
TheFile = Dir("*.xls") 'The name of the first .xls file
Do While TheFile < ""
If TheFile < ThisWorkbook.Name Then
Set wb = Workbooks.Open(MyPath & "\" & TheFile)
'At this point workbook wb is the active workbook.
'Insert your change code here
wb.Close
End If
TheFile = Dir 'The name of the next .xls file
Loop
End Sub
"WildWill" wrote in message
...
I have a range of files stored in the same location/sub-directory, and I
need
to make the same change to each one of the files. How do I achieve this by
using a Macro? My files are named 1.xls, 2.xls....50.xls


.