Understanding the CorelDRAW object model : Working with documents : Activating documents |
Each open document is a member of the Application.Documents collection. The documents in that collection appear in the order in which they were created or opened.
• |
To reflect the actual stacking order of the documents, you must use the Application.Windows
collection.
|
The Application.ActiveDocument property provides direct access to the active document that is, the document that is in front of all the other documents in the application window. ActiveDocument is an object of type Document and, therefore, has the same members properties, methods, and objects as the Document class.
If no documents are open, ActiveDocument returns nothing. You can check for open documents by using the following VBA code:
If Documents.Count = 0 Then |
MsgBox "There aren't any open documents.", vbOK, "No Docs" |
Exit Sub |
End If |
The Document.Activate method activates a document so that it can be referenced by ActiveDocument. The following VBA code activates the third open document (if three or more documents are open):
Documents(3).Activate |
• |
Using the Document.Activate method on the Application.ActiveDocument property has no effect.
|
If you want, you can specify which open document to activate by referencing the one of the following properties:
• |
Document.FilePath checks only the file path (for example, C:\My Documents)
|
• |
Document.FileName checks only the filename (for example, Graphic1.cdr)
|
• |
Document.FullFileName checks both the file path and the filename (for example, C:\My
Documents\Graphic1.cdr)
|
You can check the filename of each open document by using the following VBA code:
Public Function findDocument(filename As String) As Document |
Dim doc As Document |
For Each doc In Documents |
If doc.FileName = filename Then Exit For |
Set doc = Nothing |
Next doc |
Set findDocument = doc |
End Function |
You can then activate the returned document by using the Document.Activate method.
Copyright 2013 Corel Corporation. All rights reserved.