Protected View Now Preventing Macros From Copying, Editing, or even Identifying.

Jeffrey Mahoney

Well-known Member
Joined
May 31, 2015
Messages
3,142
Office Version
  1. 365
Platform
  1. Windows
Ok, Excel has changed again. The snippet of a macro below has worked for years, even for workbooks that are in protected view. Now it doesn't see them at all. As soon as I click Enable Editing, the macro works.

I'm really hoping this isn't permanent.

Does anybody know of a workaround?


VBA Code:
Sub FindWB()
  Dim WB As Workbook
  Dim v As Variant
  
  For Each WB In Application.Workbooks
    Debug.Print WB.Name
    
    If InStr(WB.Name, "Cash Flow Export") > 0 Or InStr(WB.Name, "Header Report") > 0 Then
      WB.Activate
      Range("A4").Select
      Set v = ActiveCell
      Exit For
    End If
  Next WB
End Sub


1703010241667.png
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Do you have any error messages?
Or what is it that no longer works?

Try the following without selecting the cell.
Make sure you have a workbook open with one of the names ("Cash Flow Export" or "Header Report"), in the same Excel application where you are running the macro.

VBA Code:
Sub FindWB()
  Dim WB As Workbook
  Dim v As Variant
  
  For Each WB In Application.Workbooks
    Debug.Print WB.Name
    
    If InStr(WB.Name, "Cash Flow Export") > 0 Or InStr(WB.Name, "Header Report") > 0 Then
      Set v = WB.Sheets(1).Range("A4")
      Exit For
    End If
  Next WB
End Sub

😇
 
Upvote 0
Hey Dante,

I debugged the macro. In the FOR loop (For Each WB In Application.Workbooks) it never sees the open workbook containing the report until I press the "Enable Editing" button. This has changed. Usually it would see the report workbook and I could get the macro to interact with it; copy data, alter the cells, and so on.

The report opens into the only instance of Excel that I already have running.

Jeff
 
Upvote 0
Dante,

I've been meaning to "Really" learn Spanish. Not just high school from 40 plus years ago. I could watch your Youtube videos.
 
Upvote 0
I've been meaning to "Really" learn Spanish. Not just high school from 40 plus years ago. I could watch your Youtube videos.
It's never too late, but you can watch the videos with English subtitles.



it never sees the open workbook containing the report until I press the "Enable Editing" button
If the workbook has protected view, you cannot see its information from VBA, it is as if it were not open, but you can try to edit the workbook from the same code, for example:


VBA Code:
Sub FindWB()
  Dim WB As Object
  Dim v As Variant
  Dim sName As String
  
  For Each WB In Application.ProtectedViewWindows
    sName = WB.SourceName
    If InStr(sName, "Cash Flow Export") > 0 Or InStr(sName, "Header Report") > 0 Then
      WB.Edit
      Set v = Workbooks(sName).Sheets(1).Range("A4")
      Exit For
    End If
  Next WB
End Sub
 
Upvote 0
Solution
I think I'll just add the code below to take away the Protected view status and then run my normal code. Thank you

VBA Code:
'Remove protected view status
  For Each WB In Application.ProtectedViewWindows
    WB.Edit
  Next WB
 
Upvote 1

Forum statistics

Threads
1,223,893
Messages
6,175,241
Members
452,622
Latest member
Laura_PinksBTHFT

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