VBA to Edit Protected View Workbooks Issue

svendiamond

Well-known Member
Joined
Jun 13, 2014
Messages
1,504
Office Version
  1. 365
Platform
  1. Windows
I have the following code which is supposed to loop through all open workbooks which are currently in "Protected View" (the yellow bar where you need to click "Edit" to be able to use the workbook) and it only loops through one or two, then stops and I don't know why.

Code:
'protected view fix
Dim bk As Workbook, w As Long, wCount As Long
wCount = Application.ProtectedViewWindows.Count
On Error Resume Next
If wCount > 0 Then
    For w = 1 To wCount
        Application.ProtectedViewWindows(w).Activate
        Application.ProtectedViewWindows(w).Edit
    Next w
End If
On Error GoTo 0

Any idea why this loop only gets some of the workbooks, some of the time? I always have six workbooks that I open from email attachments that automatically open in Protected View. And when I run this macro, it will go through two, maybe three, but it leaves the other three in Protected View. Any help is appreciated. Thanks.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Code:
Application.ProtectedViewWindows(w).Activate

Successfully activates it
 
Upvote 0
Although the problem seems to be it doesn't always work. Like, I just ran it and had three protected windows open. Stepped through the code. The first one activated, and unprotected. The second one worked too. But on the third one, the code ran but it didn't activate or unprotect the workbook.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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