Pages.Add 方法 (Visio)
将新对象添加到集合。
语法
表达式。添加
表达 一个代表 Pages 对象的变量。
返回值
Page
备注
新对象的所有属性都初始化为零,因此只需要设置您要更改的属性。
示例
以下宏显示如何将 Master 对象添加到 Masters 集合以及将 Page 对象添加到 Pages 集合。 该宏还显示如何将文档、图层、样式、事件和加载项添加到它们相应的集合。
在运行此宏之前,请将 Myfile.vsd 替换为有效的 .vsd 文件,并将 对路径 \ 文件名 和 文件名 的引用替换为对 Visio 项目中可执行加载项 (EXE) 的有效路径和/或文件名。 该加载项应该不使用任何参数。
Public Sub Add_Example()
Dim vsoMasters As Visio.Masters
Dim vsoAddons As Visio.Addons
Dim vsoPages As Visio.Pages
Dim vsoEventList As Visio.EventList
Dim vsoLayers As Visio.Layers
Dim vsoLayer As Visio.Layer
Dim vsoStyles As Visio.Styles
Dim vsoDocument As Visio.Document
Dim vsoEvent As Visio.Event
Dim vsoMaster As Visio.Master
Dim vsoPage As Visio.Page
Dim vsoShape As Visio.Shape
Dim vsoStyle As Visio.Style
Dim vsoAddon As Visio.Addon
'Add a document based on the Basic Diagram template.
Set vsoDocument = Documents.Add("Basic Diagram.vst")
'Add a document based on a drawing (creates a copy of the drawing).
Set vsoDocument = Documents.Add("Myfile.vsd ")
'Add a document based on a stencil (creates a copy of the stencil).
Set vsoDocument = Documents.Add("Basic Shapes.vss")
'Add a document object based on no template.
Set vsoDocument = Documents.Add("")
'Get the Pages collection and add a page to the collection.
Set vsoPages = vsoDocument.Pages
Set vsoPage = vsoPages.Add
'Get the Masters collection and add a master to the collection.
Set vsoMasters = vsoDocument.Masters
Set vsoMaster = vsoMasters.Add
'Get the Layers collection and add a layer named "MyLayer"
'to the collection.
Set vsoLayers = vsoPage.Layers
Set vsoLayer = vsoLayers.Add("MyLayer")
'Draw a rectangle.
Set vsoShape = vsoPage.DrawRectangle(3, 3, 5, 6)
'Add this shape to MyLayer. The second argument is required but has
'no effect, because vsoShape is not a group shape.
vsoLayer.Add vsoShape, 0
'Add a style named "My FillStyle" to the Styles collection.
'This style is based on the Basic style and includes
'only a Fill style.
Set vsoStyles = vsoDocument.Styles
Set vsoStyle = vsoStyles.Add("My FillStyle", "Basic", False, False, True)
'Add a style named "My NoStyle" to the Styles collection.
'This style is based on no style and includes
'Text, Line, and Fill styles.
Set vsoStyle = vsoStyles.Add("My NoStyle", "", True, True, True)
'Add an add-on to the Addons collection.
Set vsoAddons = Visio.Addons
Set vsoAddon = vsoAddons.Add("path \filename ")
'Add a BeforeDeleteSelection event to the EventList collection
'of the document. The event will start your add-on, which
'takes no arguments.
Set vsoEventList = vsoDocument.EventList
Set vsoEvent = vsoEventList.Add(visEvtCodeBefSelDel, visActCodeRunAddon, _
"filename ", "")
End Sub
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。