Adobe 27510753 Scripting Guide - Page 153
Closing a document, Saving a document
![]() |
UPC - 718659445294
View all Adobe 27510753 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 153 highlights
Adobe InDesign CS2 Scripting Guide Working with Documents in VBScript 145 Closing a document The Close method closes a document: Rem CloseDocument.vbs Rem An InDesign CS2 VBScript Rem Closes the active document. Set myInDesign = CreateObject("InDesign.Application.CS2") myInDesign.ActiveDocument.Close Rem Note that you could also use: Rem myInDesign.Documents.Item(1).Close For the last line, note that document 1 always refers to the front-most document. The Close method can take up to two optional parameters: Rem CloseWithParameters.vbs Rem An InDesign CS2 VBScript Rem Use idSaveOptions.idYes to save the document,idSaveOptions.idNo Rem to close the document without saving, or idSaveOptions.idAsk to Rem display a prompt. If you use idSaveOptions.idYes, you'll need to Rem provide a reference to a file to save to in the second parameter (SavingIn). Set myInDesign = CreateObject("InDesign.Application.CS2") Rem If the file has not been saved, display a prompt. If myInDesign.ActiveDocument.Saved True Then myInDesign.ActiveDocument.Close idSaveOptions.idAsk Rem Or, to save to a specific file name: Rem myFile = "c:\myTestDocument.indd" Rem myInDesign.ActiveDocument.Close idSaveOptions.idYes, myFile Else Rem If the file has already been saved, save it. myInDesign.ActiveDocument.Close idSaveOptions.idYes End If This example closes all open documents without saving them: Rem CloseAll.vbs Rem An InDesign CS2 VBScript Rem Closes all open documents without saving. Set myInDesign = CreateObject("InDesign.Application.CS2") For myCounter = myInDesign.Documents.Length To 1 Step -1 myInDesign.Documents.Item(myCounter).Close idSaveOptions.idNo Next Saving a document In the InDesign user interface, you save a file by choosing Save from the File menu, and you save a file to another file name by choosing Save As. In InDesign scripting, the Save method can do either operation: Rem SaveDocument.vbs Rem An InDesign CS2 VBScript Rem If the active document has been changed since it was last saved, save it. Set myInDesign = CreateObject("InDesign.Application.CS2") If myInDesign.ActiveDocument.Modified = True Then myInDesign.ActiveDocument.Save End If The Save method has two optional parameters: The first (To) specifies the file to save to; the second (Stationery) can be set to true to save the document as a template: Rem SaveDocumentAs.vbs Rem An InDesign C2S VBScript Rem If the active document has not been saved (ever), save it. Set myInDesign = CreateObject("InDesign.Application.CS2")
![](/manual_guide/products/adobe-27510753-scripting-guide-5f6265c/153.png)