Activating and accessing workbook with protected view (opened from potentially unsafe location)

  • Thread starter Thread starter Legacy 185660
  • Start date Start date
L

Legacy 185660

Guest
Hey Everyone!
I have a macro that checks if a workbook has been opened from sharepoint, extracts data from it and puts it in my other workbook.

My problem right now is, when I open the timesheet.xls file I get given a "Protected View This file was opened from a potentially unsafe location." "Enable Editing"

I know that if I am on the window I use the code "Application.ActiveProtectedViewWindow.Edit" but I can't get the other window to activate.

This is my code right now, basically it will not find the window that is open because it is protected

Code:
Sub ImportSheet()
    'Will activate "Timesheet less than 37.5 hours.xls" window, if it does not exist it
    'will find it. If it doesnt find it, it won't affect anything else
    On Error Resume Next
    Windows("Timesheet less than 37.5 hours.xls").Activate
    Windows("Timesheet less than 37.5 hours (1).xls").Activate
    Windows("Timesheet less than 37.5 hours (2).xls").Activate
    Windows("Timesheet less than 37.5 hours (3).xls").Activate
    Windows("Timesheet less than 37.5 hours (4).xls").Activate
    Windows("Timesheet less than 37.5 hours (5).xls").Activate
    
    
    
    'Checks to see if it has found the window to import data
    If ActiveSheet.Name <> "Error Check" Then
    
        'Checks to see if column E has been deleted yet
        If Range("F5") <> "" Then
            Columns("E:E").Delete Shift:=xlLeft
        End If
        
        'Copies data to new sheet
        Range("B5:E" & WorksheetFunction.CountA(Range("B:B")) - 2).Copy
        Windows("Time Entries.xlsm").Activate
        Range("Table8[User]").Select
        ActiveSheet.Paste
    Else
        MsgBox "Timesheet less than 37.5 hours.xls is not open" & vbNewLine & _
        "Please open the spreadsheet and recheck 'Import Sheet'", vbCritical, "Import Sheet"
    End If
    
End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Thanks! Yeah I've seen that method but I'd still prefer to do this programatically for the single document because I'm not the only computer that uses this macro. Would like to keep this as simple as possible.
 
Upvote 0
Thanks! Yeah I've seen that method but I'd still prefer to do this programatically for the single document because I'm not the only computer that uses this macro. Would like to keep this as simple as possible.
i know this is old but this should kill protect view. But i wouldnt recommend without some kind of code to verify that the correct Workbook is open. So your not unprotecting Malicious Woorkbook of some sort.


If Not Application.ActiveProtectedViewWindow Is Nothing Then
Application.ActiveProtectedViewWindow.Edit
End If
 
Upvote 0

Forum statistics

Threads
1,223,993
Messages
6,175,845
Members
452,675
Latest member
duongtruc1610

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