#1   Report Post  
Posted to microsoft.public.excel.misc
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

.

.

Reply
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
Generic file path Excel Macro Question dwake Excel Discussion (Misc queries) 5 January 28th 09 06:09 AM
Generic Macro that can rows of zeroes Daniel Excel Discussion (Misc queries) 0 August 7th 08 02:09 PM
Change a specific code to generic in VB macro Sue Excel Discussion (Misc queries) 2 April 23rd 08 06:56 PM
Generic reference in a Macro Harry's GMail World Excel Discussion (Misc queries) 2 April 17th 07 11:07 PM
Creation of a Generic Macro Sondra Excel Worksheet Functions 1 September 13th 05 10:40 PM


All times are GMT +1. The time now is 04:02 AM.

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"