Page.DropContainer method (Visio)

Creates a new container Shape object on the page, places the container around the specified target shapes, and adds the target shapes to the container. Returns the container shape.

Syntax

expression. DropContainer( _ObjectToDrop_ , _TargetShapes_ )

expression A variable that represents a Page object.

Parameters

Name Required/Optional Data type Description
ObjectToDrop Required [UNKNOWN] The container shape to add to the page. Can be a Master, MasterShortcut, Shape, or IDataObject object.
TargetShapes Required [UNKNOWN] The shapes that the container should contain. Can be a Shape or a Selection object. The shapes or selection must already be on the page.

Return value

Shape

Remarks

To pass a Master object for the ObjectToDrop parameter, use the Documents.OpenEx method and the Application.GetBuiltInStencilFile method, passing it visBuiltInStencilContainers, to open the hidden, built-in container stencil. Then use the Masters.ItemU property to get the particular container that you want from the stencil.

An IDataObject that you pass for ObjectToDrop must be provided by Microsoft Visio and must be in the same process space as Visio.

If ObjectToDrop is not a Visio object, or if it is not a container, Visio returns an Invalid Parameter error. If the value you pass is a shape that does not match the context of the method, Visio returns an Invalid Source error.

If the TargetShapes parameter is Nothing, Visio places the container shape at the center of the page, devoid of any target shapes. If the specified target shapes are not top-level members of the page, Visio returns an Invalid Parameter error.

The DropContainer method corresponds to the Insert Container command in the Visio user interface. (On the Insert tab, click Container.)

Example

The following Visual Basic for Applications (VBA) example shows how to use the DropContainer method to add a container from the hidden, built-in container stencil to the active page to contain the selected shape or shapes. Before running this macro, be sure that there is a selected shape (or a selection of shapes) on the active page.

Public Sub DropContainer_Example()

    Dim vsoDocument As Visio.Document
    Set vsoDocument = Application.Documents.OpenEx(Application.GetBuiltInStencilFile(visBuiltInStencilContainers, visMSUS), visOpenHidden)
    Application.ActivePage.DropContainer vsoDocument.Masters.ItemU("Container 1"), Application.ActiveWindow.Selection
    vsoDocument.Close
    
End Sub

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.