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

Yes, I meant unblock the cell, so that if you have protection applied you can
still add/delete data in that cell. Thanks all for the solution!

"Otto Moehrbach" wrote:

Will
You say:
2. Move to cell B22 in Sheet X and remove cell protection.
A cell doesn't have cell protection. A sheet does, but not a cell. Do you
mean that you want to UNLOCK B22? I'll assume that's what you want. Otto
Sub AllFolderFiles()
Dim wb As Workbook, TheFile As String
Dim MyPath As String, ws As Worksheet
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)
For Each ws In Sheets(Array("X", "Y", "Z"))
ws.Unprotect
Next ws
Sheets("X").Range("B22").Locked = False
Sheets("Y").Range("C39").ClearComments
Sheets("Z").Range("C6").Insert Shift:=xlDown
For Each ws In Sheets(Array("X", "Y", "Z"))
ws.Protect
Next ws
wb.Save
wb.Saved = True
wb.Close
End If
TheFile = Dir 'The name of the next .xls file
Loop
End Sub

"WildWill" wrote in message
...
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

.

.