locked
Problems with Excel 2010 Protected View (and my Add-In) RRS feed

  • Question

  • Hello!

    When I open an existing workbook and also open a workbook that will be opened in "Protected View" I got some problems with my own .xlam Add-In and its procedures

    For example:

    Sub CodeAddIn()

        Workbooks(1).Activate

    End Sub

    ...will fail with Error-Number 1004,

    the next one:

    Sub CodeAddIn()

        Application.OnKey "^d", "blabla"

    End Sub

    ...will also fail with Error-Number 1004.

     

    I know I can workaround with something like this:

    #If VBA7 Then
            If Application.ProtectedViewWindows.Count > 0 Then
                If ActiveWorkbook Is Nothing Then

                        Workbooks.Open Filename:= _
                                gstrmyEasyBusinessPfad & "\Startseite.xlsx"
                       

                       'now it works:

                        Application.OnKey "^d", "blabla"


                End If
            End If
    #End If

     

    but thats not very nice in some cases.

    Any comments???

    Best wishes, Hen from Germany

    Monday, December 5, 2011 1:30 PM

All replies

  • You can trap the error 1004, does that help?

    Something like:

    Sub CodeAddIn()
    
    On Error GoTo err_handler:
    
        Workbooks(1).Activate
    
    exit_err_handler:
    
    Exit Sub
    
    err_handler:
    
     Select Case Err.Number
      'trap error 1004
      Case 1004
       MsgBox "Opened protected view... add-in will not work!", vbCritical
      Case Else
       MsgBox "Error " & Err.Number & " " & Err.Description
     End Select
    
    Resume exit_err_handler
    
    End Sub
    



    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Monday, December 5, 2011 4:24 PM
  • Hello Daniel,

    I could do that but  you know there may be other 1004-Errors in the same procedure with other meanings.

    I just wanted to know if this is a bug or my own stupidity :-)

     

    Best wishes, Hen

    Tuesday, December 6, 2011 8:44 AM