Protected View

JerryH09

New Member
Joined
Jan 25, 2011
Messages
33
Dear All,
I occasionally get data files scraped from the web. They come in protected view and it is easy to manually enable editing so I can use the data. I would like to use those few manual keystrokes in a macro. The recorded code is:
ActiveWindow.ActivateNext
Application.ActiveProtectedViewWindow.Edit = False
ActiveWindow.ActivateNext


The ActivateNext lines are because the macro is where I want to use the data not the data files themselves but when I run it I get runtime error 91 object variable not set. I can dim Application but I've got no idea how to set it. On error resume next just ignores the application line. Any help would be much appreciated.
Regards,
JerryH09
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Activate the workbook that's open, if the protection had already been removed you would get an error, this checks to see if the protection is active and sets to false:
Code:
Windows(vWorkbookName).Activate
If Application.ProtectedViewWindows.Count > 0 Then
    Application.ActiveProtectedViewWindow.Edit
End If
 
Upvote 0
Hi GR00007 thank you so much for getting back to me. When I plug your code into mine I get:
Sub test6()
ActiveWindow.ActivateNext
If Application.ProtectedViewWindows.Count > 0 Then
Application.ActiveProtectedViewWindow.Edit
End If
ActiveWindow.ActivateNext
End Sub

I get a runtime 91 error
i'm trying to unprotectview from a different spreadsheet. If you could see a way round this I'd be very grateful
Regards,
JerryH09
 
Upvote 0
Did you try debug to determine which line is causing the error?
If you step through the code you can watch which window is active.
 
Upvote 0
Hi GR00007, It's the fourth line of code starting application. Excel seems to want this defined.
regards,
JerryH09
 
Upvote 0
Hi GR00007 Your code works great when applied to the scraped file but it's my use of ActiveWindow.ActivateNext that's causing the problem. Have you any idea how to activate a workbook without calling it by name? I would like to activate workbookname in your code but the name changes daily so I don't know the name when I'm trying to get data from it.(eg Worksheets(2).activate) If you can't so be it but your help has been very much appreciated anyway
 
Upvote 0
Are you trying to open the most recent file in a directory? Is the file from email? The source of the file determines the method of trying to get it.
I have a routine for grabbing the most recent file in a directory, but at a loss email delivery scraping.
 
Upvote 0
Hi GR0007,
I have spent weeks trying to sort this out and pissed off one of your fellow board members in the process (no names mule999) but thanks to your great bit of coding it is all coming together. I had a lightbulb moment last night and thought if I can't access the protected view file from my macro why can't I access my macro from the protected view file AND IT WORKS. I can't show you experts anything about Excel but I intend showing my gratitude by spending the next six months helping others on the MrExcel platform.
People like you make this work.
Thanks again
Jerry Hodgkinson
PS If you've already received this then apologies
PPS I've already helped one person who didn't know how to use Application.screenupdating = false
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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