Class ProtectedViewWindow (Excel VBA)

The class ProtectedViewWindow represents a Protected View window.

The main procedures of class ProtectedViewWindow are Activate, Close and ProtectedViewWindows.Open

Set

To use a ProtectedViewWindow class variable it first needs to be instantiated, for example

Dim strIndex As String: strIndex = 
Dim pvwProtectedViewWindow As ProtectedViewWindow
Set pvwProtectedViewWindow = Application.ProtectedViewWindows(Index:=strIndex)

The following procedures can be used to set variables of type ProtectedViewWindow: Application.ActiveProtectedViewWindow, ProtectedViewWindows.Item, ProtectedViewWindows.Open and Application.ProtectedViewWindows

For Each

Here is an example of processing the ProtectedViewWindow items in a collection.

Dim pvwProtectedViewWindow As ProtectedViewWindow
For Each pvwProtectedViewWindow In Application.ProtectedViewWindows
	
Next pvwProtectedViewWindow

Methods

These are the main methods of the ProtectedViewWindow class

Activate - Brings the Protected View window to the front of the z-order.

Close - Closes the specified Protected View window.

ProtectedViewWindows.Open - Opens the specified workbook in a new Protected View window.

ProtectedViewWindows.Open FileName:="C:\MyFiles\MyWorkbook.xls" 

Other Methods

Edit - Opens the workbook that is open for editing in the specified Protected View window.

Dim pvWbk As Workbook 
 
Set pvWbk = ActiveProtectedViewWindow.Edit 

Properties

Caption returns or sets a value that represents the name that appears in the title bar of the Protected View window.

MsgBox "The name of the active Protected View window is " & ActiveProtectedWindow.Caption

EnableResize true if the Protected View window can be resized.

ActiveProtectedViewWindow.EnableResize = False

Height returns or sets a value that represents the height, in points, of the Protected View window.

Left returns or sets a value that represents the distance, in points, from the left edge of the client area to the left edge of the Protected View window.

SourceName returns the name of the source file that is open in the specified Protected View window.

MsgBox ActiveProtectedViewWindow.SourcePath & "\" _ 
 & ActiveProtectedViewWindow.SourceName

SourcePath returns the path of the source file that is open in the specified Protected View window.

MsgBox ActiveProtectedViewWindow.SourcePath & Application.PathSeparator _ 
 & ActiveProtectedViewWindow.SourceName 

Top returns or sets a value that represents the distance, in points, from the top edge of the specified Protected View window to the top edge of the usable area.

Visible returns or sets a value that determines whether the specified Protected View window is visible.

Width returns or sets a value that specifies the width, in points, of the specified Protected View window.

WindowState returns or sets the state of the specified Protected View window.

ActiveProtectedViewWindow.WindowState = xlProtectedViewWindowMaximized 

Workbook returns an object that represents the workbook that is open in the specified Protected View window.

Dim wbProtected As Workbook 
 
If Application.ProtectedViewWindows.Count > 0 Then 
    Set wbProtected = Application.ProtectedViewWindows(1).Workbook 
End If 

ProtectedViewWindows.Count returns a Long value that represents the number of objects in the collection.

ProtectedViewWindows.Item returns a single object from a collection.

ProtectedViewWindows.Parent returns the parent object for the specified object. Read-only.