Documents object (Publisher)

Represents all open publications. The Documents collection contains all Document objects that are open in Microsoft Publisher.

Remarks

Use the Documents property to return the Documents collection.

Use the Add method to add a new document to the collection. A new and visible instance of Publisher is created when the Add method is called.

Use the Item (index) property, where index is the index number or document name as a String, to return a specific document object.

Example

The following example lists all the open publications.

Dim objDocument As Document 
Dim strMsg As String 
For Each objDocument In Documents 
 strMsg = strMsg & objDocument.Name & vbCrLf 
Next objDocument 
MsgBox Prompt:=strMsg, Title:="Current Documents Open", Buttons:=vbOKOnly

The following example adds a new document to the Documents collection.

Dim objDocument As Document 
Set objDocument = Documents.Add 
With objDocument 
 .LayoutGuides.Columns = 4 
 .LayoutGuides.Rows = 9 
 .ActiveView.Zoom = pbZoomWholePage 
End With

The following example displays the name of the first open publication.

If Documents.Count >= 1 Then 
 MsgBox Documents.Item(1).Name 
End If 


The following example checks the name of each document in the Documents collection. If the name of a document is Sales.doc, an object variable objSalesDoc is set to that document in the Documents collection.

Dim objDocument As Document 
Dim objSalesDoc As Document 
For Each objDocument In Documents 
 If objDocument.Name = "Sales.doc" Then 
 Set objSalesDoc = objDocument 
 End If 
Next objDocument

Methods

Properties

See also

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.