Hi Team,
I have split of 100 files and need to do a password protect all of them. Can this be done via macro. Password remains same for all the files.
Kind Regards,
Hi Team,
I have split of 100 files and need to do a password protect all of them. Can this be done via macro. Password remains same for all the files.
Kind Regards,
Keep the Forum clean :
1. Use [ code ] code tags [ /code ]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
2. Show appreciation to those who have helped you by clicking * Add Reputation below their posts.
3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.
This is one way. Assume your file names are listed in column A.
![]()
Sub t() Dim wb As Workbook, c As Range For Each c In Range("A1", Cells(Rows.Count, 1).End(xlUp)) Set wb = Workbooks.Open(ThisWorkbook.Path & "\" & c.Value) wb.Protect Password:="Password" 'substitute your password here wb.Close True Next End Sub
Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
Just when I think I am smart, I learn something new!
Thanks JLGWhiz,
Macro opens up the file, but password is not set. It just closed the file by opening it.
Please advise.
Thanks,
This should work.
![]()
Sub test() Dim wb As Workbook, c As Range For Each c In Range("A1", Range("A" & Rows.Count).End(xlUp)) Workbooks.Open ThisWorkbook.Path & "\" & c.Value With ActiveWorkbook Application.DisplayAlerts = False .SaveAs ActiveWorkbook.FullName, , "password" Application.DisplayAlerts = True .Close False End With Next End Sub
Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks