Unprotect multiple files, & do search and replace

natief

New Member
Joined
Apr 11, 2008
Messages
16
Good day,

I have ±70 .xls files in one directory.

I need to unprotect the 1st sheet in each workbook, replace the content of a specific cell (some text in there), and reprotect the sheets.

I am sure there must be a better way than to do it manually, any assistance appreciated.

Thank you.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
59,294
Office Version
  1. 365
Platform
  1. Windows
First, make sure you have a backup of the directory.

Then try this code. It assumes the first sheet of each workbook has no password to unprotect. If that is not the case, hopefully they all have the same password and the code could easily be modified to cope with that. I don't think this code will work with Excel 2007.

In the code, you would need to amend the path, the cell address you want to change and the text you want to insert in that cell.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Test()<br>    <SPAN style="color:#00007F">Dim</SPAN> mypath <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>    <br>    Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br>    mypath = "C:\myExcelFiles\"<br>    <SPAN style="color:#00007F">With</SPAN> Application.FileSearch<br>        .NewSearch<br>        .LookIn = mypath<br>        .SearchSubFolders = <SPAN style="color:#00007F">False</SPAN><br>        .Filename = "*.xls"<br>        .MatchTextExactly = <SPAN style="color:#00007F">True</SPAN><br>        .FileType = msoFileTypeAllFiles<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <br>    <SPAN style="color:#00007F">With</SPAN> Application.FileSearch<br>        <SPAN style="color:#00007F">If</SPAN> .Execute() > 0 <SPAN style="color:#00007F">Then</SPAN><br>            <SPAN style="color:#00007F">For</SPAN> i = 1 <SPAN style="color:#00007F">To</SPAN> .FoundFiles.Count<br>                Workbooks.Open (.FoundFiles(i))<br>                <SPAN style="color:#00007F">With</SPAN> ActiveWorkbook.Sheets(1)<br>                    .Unprotect<br>                    .Range("E10").Value = "myNewText"<br>                    .Protect<br>                    .Parent.Close (True)<br>                <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>            <SPAN style="color:#00007F">Next</SPAN> i<br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br>    MsgBox "Process complete"<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0

natief

New Member
Joined
Apr 11, 2008
Messages
16
They are password protected, and in Office 2007, so that seems to be a problem.

Thank you.
 
Upvote 0

Forum statistics

Threads
1,191,709
Messages
5,988,236
Members
440,139
Latest member
ngaicuong2017

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top