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.
Version Information
Version Added: Visio 2010
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