Macro cannot "see" protected view file

sadoul

New Member
Joined
Apr 5, 2019
Messages
10
Hello guys,

So i created a command button macro that locate a file with a specific name but it seems that if the file is in "protected view", the macro cannot locate the file...
If i enable editing, it does work... If i don't it can't locate the file
I feel like i tried everything

Application.ActiveProtectedViewWindow.Edit
or
If Application.ProtectedViewWindows.Count > 0 Then
Application.ActiveProtectedViewWindow.Edit
End If
or
Unprotect



See macro below... Let me know what you think, i always get MsgBox ("There is no file currently open.") if i don't click on EDIT
Thanks for your help

Sub TD_Click()


Dim UtilWb As Workbook, Wb As Workbook




For Each Wb In Application.Workbooks
If Wb.Name Like "Fake name*" Then
Set UtilWb = Wb
Exit For
End If
Next Wb


If UtilWb Is Nothing Then
MsgBox ("There is no file currently open.")
'Ends macro if there is no util file
End
End If


'UtilWb.ActiveProtectedViewWindow.Edit
'UtilWb.Unprotect Password:=""
UtilWb.Activate
'If Application.ProtectedViewWindows.Count > 0 Then
'Application.ActiveProtectedViewWindow.Edit
'End If




End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Sorry about my last post. It should have read. The code I gave you looks for protected view worksheets and if it finds any it allows editing. So if you manually allow editing no problem. The code I gave you will do nothing and your macro should be fine.
Cheers,
Jerry
 
Upvote 0

Forum statistics

Threads
1,216,033
Messages
6,128,427
Members
449,450
Latest member
gunars

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