Reputation: 81
How can I detect all open Excel files and run through them, in order to lock their sheets?
I have an Excel file containing the macro. Once it is launched, it would go through all my open excel files, and lock their sheets by setting a password.
Just don't know how to detect open Excel files from VBA.
Upvotes: 1
Views: 217
Reputation: 14547
You just have to loop on the workbooks in Application
:
Dim wB as WorkBook
Dim wS as WorkSheet
For Each wB in Application.WorkBooks
For Each wS in wB.Sheets
wS.Protect "password"
Next wS
Next wB
Upvotes: 1