How do I use a macro to put a password on an exel file with excel 2010

Skeve3

New Member
Joined
Sep 29, 2014
Messages
1
Hi All .

I previously used the following macro to put a password on all excel files within the specified network directory. Now that I have moved over to excel 2010 this macro no longer works on either xls or xlsm files. Any help would be appreciated.

I previously use the following macro to put a password on all files within the specified network directory. Now that I have moved over to excel 2010 this macro no longer works on either xls or xlsm files. Any help would be appreciated.</SPAN>


Sub OpenAndProcess()</SPAN></SPAN>
Dim vaFileName As Variant</SPAN></SPAN>
Const MyDir As String = "W:\network folder path"</SPAN></SPAN></SPAN>
Const strPwd As String = "****password****</SPAN>"</SPAN></SPAN>

With Application.FileSearch</SPAN></SPAN>
.NewSearch</SPAN></SPAN>
.LookIn = MyDir</SPAN></SPAN>
.SearchSubFolders = False</SPAN></SPAN>
.FileType = msoFileTypeExcelWorkbooks</SPAN></SPAN>
If .Execute > 0 Then</SPAN></SPAN>
Application.ScreenUpdating = False</SPAN></SPAN>
For Each vaFileName In .FoundFiles</SPAN></SPAN>
ProcessData vaFileName, strPwd</SPAN></SPAN>
Next</SPAN></SPAN>
Else</SPAN></SPAN>
MsgBox "There were no Excel files found."</SPAN></SPAN>
End If</SPAN></SPAN>
Application.ScreenUpdating = True</SPAN></SPAN>
End With</SPAN></SPAN>

End Sub</SPAN></SPAN>

Sub ProcessData(ByVal Fname As String, Pwd As String)</SPAN></SPAN>
Dim wbk As Workbook</SPAN></SPAN>

Set wbk = Workbooks.Open(Filename:=Fname)</SPAN></SPAN>

With wbk</SPAN></SPAN>
Application.DisplayAlerts = False</SPAN></SPAN>
.SaveAs Filename:=Fname, Password:=Pwd</SPAN></SPAN>
Application.DisplayAlerts = True</SPAN></SPAN>
.Close</SPAN></SPAN>
End With</SPAN></SPAN>

End Sub</SPAN></SPAN>
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Still not able to get this to work with excel 2010 and .XLSX files anyone able to post an updated code?
 
Upvote 0

Forum statistics

Threads
1,215,596
Messages
6,125,728
Members
449,255
Latest member
whatdoido

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
Back
Top