none
Can you take action when the resolution changes for excel document customizations? RRS feed

  • Question

  • Hi,

    If an end user changes the screen resolution while an excel document customization is running, is it possible to take action automatically on the resolution change event?

    I am coding the customization in vb.net.

    For example:

    1. User opens document customization

    2. User changes screen resolutoin with document customization open

    3. Code executes based on the screen resolution change event

    Thanks!

    Friday, February 17, 2012 11:07 PM

Answers

  • Hi DTD122,

    Thanks for posting in the MSDN Forum.

    According to your description I suppose that you want to subscribe to window/protected view window's event. I provide the follow snippet to you. I hope it can help you.

    Public Class ThisWorkbook
        Private WithEvents xlApp As Excel.Application
    
        Private Sub ThisWorkbook_Startup() Handles Me.Startup
            xlApp = Globals.ThisWorkbook.Application
    
        End Sub
    
        Private Sub ThisWorkbook_Shutdown() Handles Me.Shutdown
    
        End Sub
    
        Private Sub xlApp_WindowActive(ByVal Wb As Excel.Workbook, _
            ByVal Wn As Excel.Window) Handles xlApp.WindowActivate
            MsgBox("Window active")
        End Sub
    
        Private Sub xlApp_WindowDeactive(ByVal Wb As Excel.Workbook, _
            ByVal Wn As Excel.Window) Handles xlApp.WindowDeactivate
            MsgBox("Window deactive")
        End Sub
    
        Private Sub xlApp_WindowResize(ByVal Wb As Excel.Workbook, _
            ByVal Wn As Excel.Window) Handles xlApp.WindowResize
            MsgBox("Window resize")
        End Sub
    
        Private Sub xlApp_ProtectedViewWindowActivate _
            (ByVal PvWn As Excel.ProtectedViewWindow) Handles _
            xlApp.ProtectedViewWindowActivate
            MsgBox("ProtectedViewWindow active")
        End Sub
    
        Private Sub xlApp_ProtectedViewWindowOpen _
            (ByVal Pvm As Excel.ProtectedViewWindow) Handles _
            xlApp.ProtectedViewWindowOpen
            MsgBox("ProtectedViewWindow Open")
        End Sub
    
        Private Sub xlApp_ProtectedViewWindowResize _
            (ByVal Pvm As Excel.ProtectedViewWindow) Handles _
            xlApp.ProtectedViewWindowResize
            MsgBox("ProtectedViewWindow Resize")
        End Sub
    
        Private Sub xlApp_ProtectedViewWindowBeforeEdit _
            (ByVal Pvm As Excel.ProtectedViewWindow, ByRef Cancel As Boolean) _
            Handles xlApp.ProtectedViewWindowBeforeEdit
            MsgBox("ProtectedViewWindow Before Edit")
        End Sub
    
        Private Sub xlApp_ProtectedViewWindowBeforeClose _
            (ByVal Pvm As Excel.ProtectedViewWindow, _
             ByVal Reson As Excel.XlProtectedViewCloseReason, _
             ByRef Cancel As Boolean) _
         Handles xlApp.ProtectedViewWindowBeforeClose
            MsgBox("ProtectedViewWinodw befor close")
        End Sub
    
        Private Sub xlApp_ProtectedViewWindowDeactivate _
            (ByVal Pvm As Excel.ProtectedViewWindow) _
            Handles xlApp.ProtectedViewWindowDeactivate
            MsgBox("ProtectedViewWinodw deactive")
        End Sub
    
    End Class

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by DTD122 Monday, March 5, 2012 6:28 PM
    Monday, February 20, 2012 6:20 AM
    Moderator

All replies

  • Hi DTD122,

    Thanks for posting in the MSDN Forum.

    According to your description I suppose that you want to subscribe to window/protected view window's event. I provide the follow snippet to you. I hope it can help you.

    Public Class ThisWorkbook
        Private WithEvents xlApp As Excel.Application
    
        Private Sub ThisWorkbook_Startup() Handles Me.Startup
            xlApp = Globals.ThisWorkbook.Application
    
        End Sub
    
        Private Sub ThisWorkbook_Shutdown() Handles Me.Shutdown
    
        End Sub
    
        Private Sub xlApp_WindowActive(ByVal Wb As Excel.Workbook, _
            ByVal Wn As Excel.Window) Handles xlApp.WindowActivate
            MsgBox("Window active")
        End Sub
    
        Private Sub xlApp_WindowDeactive(ByVal Wb As Excel.Workbook, _
            ByVal Wn As Excel.Window) Handles xlApp.WindowDeactivate
            MsgBox("Window deactive")
        End Sub
    
        Private Sub xlApp_WindowResize(ByVal Wb As Excel.Workbook, _
            ByVal Wn As Excel.Window) Handles xlApp.WindowResize
            MsgBox("Window resize")
        End Sub
    
        Private Sub xlApp_ProtectedViewWindowActivate _
            (ByVal PvWn As Excel.ProtectedViewWindow) Handles _
            xlApp.ProtectedViewWindowActivate
            MsgBox("ProtectedViewWindow active")
        End Sub
    
        Private Sub xlApp_ProtectedViewWindowOpen _
            (ByVal Pvm As Excel.ProtectedViewWindow) Handles _
            xlApp.ProtectedViewWindowOpen
            MsgBox("ProtectedViewWindow Open")
        End Sub
    
        Private Sub xlApp_ProtectedViewWindowResize _
            (ByVal Pvm As Excel.ProtectedViewWindow) Handles _
            xlApp.ProtectedViewWindowResize
            MsgBox("ProtectedViewWindow Resize")
        End Sub
    
        Private Sub xlApp_ProtectedViewWindowBeforeEdit _
            (ByVal Pvm As Excel.ProtectedViewWindow, ByRef Cancel As Boolean) _
            Handles xlApp.ProtectedViewWindowBeforeEdit
            MsgBox("ProtectedViewWindow Before Edit")
        End Sub
    
        Private Sub xlApp_ProtectedViewWindowBeforeClose _
            (ByVal Pvm As Excel.ProtectedViewWindow, _
             ByVal Reson As Excel.XlProtectedViewCloseReason, _
             ByRef Cancel As Boolean) _
         Handles xlApp.ProtectedViewWindowBeforeClose
            MsgBox("ProtectedViewWinodw befor close")
        End Sub
    
        Private Sub xlApp_ProtectedViewWindowDeactivate _
            (ByVal Pvm As Excel.ProtectedViewWindow) _
            Handles xlApp.ProtectedViewWindowDeactivate
            MsgBox("ProtectedViewWinodw deactive")
        End Sub
    
    End Class

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by DTD122 Monday, March 5, 2012 6:28 PM
    Monday, February 20, 2012 6:20 AM
    Moderator
  • Thanks Tom!

    I think this will help.

    I will mark this as the answer for now, and if I have any other difficulties, I'll repost.

    Thanks!

    Monday, March 5, 2012 6:28 PM