Searches for a document with the specified name (Name property) among the open documents of the application. Returns an instance of the Document object corresponding to the found document.
Applies to: Application object
[[Set] documentRet =] object.DocByName ( docName ) |
The DocByName method syntax has these parts:
Part | Description |
object | Required. An expression that returns an instance of the Application object. |
docName | Required. An expression that returns a String value. The name (Name property) of the document being searched. |
documentRet | Optional. A Document type variable. |
The DocByName method searches for a document with the docName name starting from the first document in the document collection and returns the first found document. That is, if the third and fifth document have the same name, the DocByName method will returns the instance of the Document object that corresponds to the third document. If there is no matching document, the method returns Nothing.
This example contains an application-level script. The program first askes the user to enter the name of the document and then searches for the the document with the provided name. If the search is successfu, it maximizes the active window of the found document.
' Declare variables Dim inStr As String Dim resDoc As Document ' Show the dialog where to input the document name Set inStr = InputBox( "Enter document name:", "Document by name!", "Concept1.cdd" ) ' Find the specified document Set resDoc = thisApp.DocByName( inStr ) ' If the document is found, activate it If resDoc <> Nothing Then resDoc.ActiveView.Maximize() ' Otherwise inform the user Else MsgBox( "The document " & inStr & " is not found!" ) End If |
See Also |
Name property, CloseDoc method, CreateNewDoc method, Doc method, DocsNum method, FirstDoc method, NextDoc method, OpenDoc method, Document object |